Re: problem with pl/pgsql function unknown parameters

Поиск
Список
Период
Сортировка
От Jules Alberts
Тема Re: problem with pl/pgsql function unknown parameters
Дата
Msg-id 20030212122804.AF7FB1CB200@koshin.dsl.systemec.nl
обсуждение исходный текст
Ответ на problem with pl/pgsql function unknown parameters  ("Jules Alberts" <jules.alberts@arbodienst-limburg.nl>)
Ответы Re: problem with pl/pgsql function unknown parameters  (Dmitry Tkach <dmitry@openratings.com>)
Список pgsql-novice
Op 11 Feb 2003 (14:26), schreef Dmitry Tkach <dmitry@openratings.com>:

Hello Dmitry, thanks for your reaction.

> Make it text:
> (this example is in sql - I suppose, you could do the same thing in pl):
>
> create or replace function is_empty (text) returns boolean as 'select $1 is null or $1=\'\'' language 'sql' with
(iscachable);
>
> select is_empty('Blah');
> false
> select is_empty ('2');
> false
> select is_empty ('');
> true
> select is_empty (null);
> true

select is_empty();
ERROR:  Function 'is_empty()' does not exist
Unable to identify a function that satisfies the given argument types
You may need to add explicit typecasts

> As for the 'no arg version' (I don't understand why you need it actually),

Defensive programming. I want my functions to behave nicely, even if
they have no idea what's coming at them. If a function gets no
parameter, it could default to a hardcoded value. IMO this is very
useful, I find it strange that postgresql doesn't allow this.

> you'd have to have a separate func:
> create or replace function is_empty () returns boolean as 'select true;' language 'sql'  with (iscachable);
>
> select is_empty();
> true
>
> I hope, it helps...
>
> Dima

Another example of a useful function (semi-code):

function showtype(unspecified) returns text {
    raise notice ''%'', datatype($1);
}

I guess that if I wanted to do this in postgresql I would have to make
a function for every possible datatype. Not very efficient :-(

В списке pgsql-novice по дате отправления:

Предыдущее
От: Peter Childs
Дата:
Сообщение: Re: How can i combine two columns
Следующее
От: César Eduardo Schneider
Дата:
Сообщение: Re: locale error