From: | Michael J Davis <michael(dot)j(dot)davis(at)tvguide(dot)com> |
---|---|
To: | pgsql-sql(at)postgreSQL(dot)org |
Subject: | RE: [SQL] null values to be replaced by a default value |
Date: | 1999-04-20 17:13:37 |
Message-ID: | 93C04F1F5173D211A27900105AA8FCFC1453EE@lambic.prevuenet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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(at)valigene(dot)com]
Sent: Tuesday, April 20, 1999 9:32 AM
To: pgsql-sql(at)postgreSQL(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 1999-04-20 17:20:40 | Re: [SQL] null values to be replaced by a default value |
Previous Message | Nuchanard Chiannilkulchai | 1999-04-20 15:31:41 | null values to be replaced by a default value |