pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nuchanard Chiannilkulchai <nuch@valigene.com>
To: pgsql-sql@postgreSQL.org
Subject: null values to be replaced by a default value
Date: Tue, 20 Apr 1999 17:31:41 +0200
Message-ID: <371C9DDD.AC4ED97B@valigene.com> (raw)

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





view thread (3+ messages)  latest in thread

Message-ID: <371C9DDD.AC4ED97B@valigene.com>
Permalink:  ../371C9DDD.AC4ED97B@valigene.com/
Also on:    postgresql.org/message-id/371C9DDD.AC4ED97B@valigene.com

 · 

reply

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: nuch@valigene.com
  Subject: Re: null values to be replaced by a default value
  In-Reply-To: <371C9DDD.AC4ED97B@valigene.com>
  References: <371C9DDD.AC4ED97B@valigene.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