pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Nuchanard Chiannilkulchai <nuch@valigene.com>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] null values to be replaced by a default value
Date: Tue, 20 Apr 1999 13:20:40 -0400
Message-ID: <14253.924628840@sss.pgh.pa.us> (raw)
In-Reply-To: <371C9DDD.AC4ED97B@valigene.com>

Nuchanard Chiannilkulchai <nuch@valigene.com> writes:
>     To return one value not null, i've created a function :

You can't really do that with functions right now --- any null
input to a function causes the result to be null.  (There's
been discussion on the hackers list about improving this,
but it won't happen before 6.6 at the earliest.)

Fortunately, the standard COALESCE operator does what you want
already: COALESCE(a,b) produces the result you were looking for,
and you won't need to make a new copy for every data type either.

Basically, COALESCE takes any number of arguments and returns the
first one that's not NULL.  It's a shorthand for a CASE expression,
(CASE WHEN a IS NOT NULL THEN a WHEN b IS NOT NULL THEN b ...)

			regards, tom lane



view thread (3+ messages)

Message-ID: <14253.924628840@sss.pgh.pa.us>
Permalink:  ../14253.924628840@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/14253.924628840@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, nuch@valigene.com
  Subject: Re: [SQL] null values to be replaced by a default value
  In-Reply-To: <14253.924628840@sss.pgh.pa.us>
  References: <371C9DDD.AC4ED97B@valigene.com> <14253.924628840@sss.pgh.pa.us>

* 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