From: Michael J Davis <michael.j.davis@tvguide.com>
To: pgsql-sql@postgreSQL.org
Subject: RE: [SQL] null values to be replaced by a default value
Date: Tue, 20 Apr 1999 12:13:37 -0500
Message-ID: <93C04F1F5173D211A27900105AA8FCFC1453EE@lambic.prevuenet.com> (raw)
I would really like to be able to do the same thing!!! The following
function seems to work okay:
CREATE FUNCTION nz (int4) RETURNS int4 AS '
BEGIN
IF ($1 IS NULL) THEN
RETURN 0;
ELSE
RETURN $1;
END IF;
END;
' LANGUAGE 'plpgsql';
-----Original Message-----
From: Nuchanard Chiannilkulchai [SMTP:nuch@valigene.com]
Sent: Tuesday, April 20, 1999 9:32 AM
To: pgsql-sql@postgreSQL.org
Subject: [SQL] null values to be replaced by a default value
Hi,
To return one value not null, i've created a function :
CREATE FUNCTION isnull (int4,int4 ) RETURNS int4 AS '
BEGIN
IF ($1 IS NULL) THEN
RETURN $2;
ELSE
RETURN $1;
END IF;
END;
' LANGUAGE 'plpgsql';
select isnull(my_int,0) as number, sample_id from my_table;
but I got
number |sample_id
------+---------
| 13
| 15
What should I do to have '0' in the column 'number' instead of NULL
?
Thanks,
nuch
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: michael.j.davis@tvguide.com
Subject: Re: [SQL] null values to be replaced by a default value
In-Reply-To: <93C04F1F5173D211A27900105AA8FCFC1453EE@lambic.prevuenet.com>
References: <93C04F1F5173D211A27900105AA8FCFC1453EE@lambic.prevuenet.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