From: | Joel Burton <jburton(at)scw(dot)org> |
---|---|
To: | Nikola Milutinovic <Nikola(dot)Milutinovic(at)ev(dot)co(dot)yu> |
Cc: | PostgreSQL general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: PL/PgSQL bug? |
Date: | 2001-07-25 15:18:17 |
Message-ID: | Pine.LNX.4.21.0107251113450.19406-100000@olympus.scw.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Wed, 25 Jul 2001, Nikola Milutinovic wrote:
> Hi all.
>
> I have noticed a strange bug/feature in PL/PgSQL language. Whenever I pass 'null' as one of the parameters, every argument becomes 'null'.
>
> For example:
>
> CREATE FUNCTION div_mod( int4, text, int4, bool, int2 ) RETURNS int4 AS '
> BEGIN
> IF $1 ISNULL THEN
> RETURN 2;
> END IF;
> RETURN 0;
> END;
> ' LANGUAGE 'plpgsql';
>
> Now perform:
> mercury# select div_mod( 1, 'Test', null, 't' 10 );
> div_mod
> -----------
> 2
>
> Although the function is called with $1 = 1, it is 'null' in this case. Actually all $n parameters are 'null'. PostgreSQL version is:
>
> mercury=# select version();
> version
> --------------------------------------------------------
> PostgreSQL 7.0.2 on alpha-dec-osf4.0f, compiled by cc
> (1 row)
>
> Is this a bug or a feature?
Bug or feature? You pick.
The argument would be something like, "if an argument is null, you're
saying you don't know what it is; therefore, how could we predict the
outcome of this set of arguments, one of which is unknown." It's very
SQL-like (NULLs meanining 'unknown', not just 'blank').
However, it does make for painful functional programming.
In 7.1, this is fixed (or if you thought it wasn't broken, it's
*changed* -- though you can specify in 7.1 to use the old,
NULL-as-utterly-unknown meaning for function arguments).
In 7.0.x, you could COALESCE or CASE your NULL to something else, then
have your function handle that.
hth,
--
Joel Burton <jburton(at)scw(dot)org>
Director of Information Systems, Support Center of Washington
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2001-07-25 15:21:43 | Re: More.. Re: Changes to C interface from 7.0 to 7.1 |
Previous Message | Josh Berkus | 2001-07-25 15:14:09 | Re: Re: Inserts in triggers Follow Up |