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:32AMTo: pgsql-sql@postgreSQL.orgSubject: [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 gotnumber |sample_id------+--------- | 13 | 15
What should I do to have '0' in the column 'number' instead of NULL
?Thanks,
nuch