Re: problem with pl/pgsql function unknown parameters - Mailing list pgsql-novice

From Jules Alberts
Subject Re: problem with pl/pgsql function unknown parameters
Date
Msg-id 20030212122804.AF7FB1CB200@koshin.dsl.systemec.nl
Whole thread Raw
In response to problem with pl/pgsql function unknown parameters  ("Jules Alberts" <jules.alberts@arbodienst-limburg.nl>)
Responses Re: problem with pl/pgsql function unknown parameters
List 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 by date:

Previous
From: Peter Childs
Date:
Subject: Re: How can i combine two columns
Next
From: César Eduardo Schneider
Date:
Subject: Re: locale error