From: | "Jules Alberts" <jules(dot)alberts(at)arbodienst-limburg(dot)nl> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Cc: | Dmitry Tkach <dmitry(at)openratings(dot)com> |
Subject: | Re: problem with pl/pgsql function unknown parameters |
Date: | 2003-02-12 12:27:33 |
Message-ID: | 20030212122804.AF7FB1CB200@koshin.dsl.systemec.nl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Op 11 Feb 2003 (14:26), schreef Dmitry Tkach <dmitry(at)openratings(dot)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 :-(
From | Date | Subject | |
---|---|---|---|
Next Message | César Eduardo Schneider | 2003-02-12 12:38:58 | Re: locale error |
Previous Message | Peter Childs | 2003-02-12 11:40:14 | Re: How can i combine two columns |