From: Jie Liang <jliang@ipinc.com>
To: Andrew Perrin <aperrin@socrates.berkeley.edu>
Cc: pgsql-sql@postgresql.org
Subject: Re: PL/PgSQL and NULL
Date: Sun, 11 Mar 2001 17:58:40 -0800 (PST)
Message-ID: <Pine.BSF.4.10.10103111747170.78730-100000@tidal.ipinc.com> (raw)
In-Reply-To: <Pine.LNX.4.21.0103111536210.6221-100000@nujoma.perrins>
I think that is a bug in plpgsql,
when passing a NULL into a plpgsql defined function, it treats
other arguments as NULL also, you can use raise notice in
your function to watch this buggy thing(see following).
Jie LIANG
St. Bernard Software
10350 Science Center Drive
Suite 100, San Diego, CA 92121
Office:(858)320-4873
jliang@ipinc.com
www.stbernard.com
www.ipinc.com
On Sun, 11 Mar 2001, Andrew Perrin wrote:
> Greetings-
>
> I'm trying to write what should be a simple function that returns the
> minimim of two integers. The complication is that when one of the two
> integers is NULL, it should return the other; and when both are NULL, it
> should return NULL. Here's what I've written:
>
> CREATE FUNCTION min(int4, int4)
> RETURNS int4
> AS 'BEGIN
raise notice ''arg1 is % arg2 is %'',$1,$2; -- debugging
> IF $1 ISNULL
> THEN
> RETURN $2;
> ELSE
> IF $2 ISNULL
> THEN
> RETURN $1;
> ELSE
> IF $1 > $2
> THEN
> RETURN $2;
> ELSE
> RETURN $1;
> END IF;
> END IF;
> END IF;
> END;'
> LANGUAGE 'plpgsql';
>
> and here's what I get:
>
> fgdata=# select min(10, NULL);
> min
> -----
>
> (1 row)
>
> so it looks like, for whatever reason, it's returning NULL when it should
> be returning 10. Can anyone offer advice?
>
> Thanks.
>
> ----------------------------------------------------------------------
> Andrew J Perrin - Ph.D. Candidate, UC Berkeley, Dept. of Sociology
> Chapel Hill, North Carolina, USA - http://demog.berkeley.edu/~aperrin
> aperrin@socrates.berkeley.edu - aperrin@igc.apc.org
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: jliang@ipinc.com, aperrin@socrates.berkeley.edu
Subject: Re: PL/PgSQL and NULL
In-Reply-To: <Pine.BSF.4.10.10103111747170.78730-100000@tidal.ipinc.com>
References: <Pine.LNX.4.21.0103111536210.6221-100000@nujoma.perrins> <Pine.BSF.4.10.10103111747170.78730-100000@tidal.ipinc.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox