null values to be replaced by a default value

From: Nuchanard Chiannilkulchai <nuch(at)valigene(dot)com>
To: pgsql-sql(at)postgreSQL(dot)org
Subject: null values to be replaced by a default value
Date: 1999-04-20 15:31:41
Message-ID: 371C9DDD.AC4ED97B@valigene.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

Browse pgsql-sql by date

  From Date Subject
Next Message Michael J Davis 1999-04-20 17:13:37 RE: [SQL] null values to be replaced by a default value
Previous Message Dirk Lutzebaeck 1999-04-20 15:11:42 SELECT LIMIT not working with unions?