From: Tom Lane <tgl@sss.pgh.pa.us>
To: Glenn Waldron <gwaldron@wareonearth.com>
Cc: pgsql-sql@hub.org
Subject: Re: [SQL] Trouble with null text fields!
Date: Sun, 18 Apr 1999 13:51:32 -0400
Message-ID: <26721.924457892@sss.pgh.pa.us> (raw)
In-Reply-To: <199904140300.XAA22576@hub.org>
"Glenn Waldron" <gwaldron@wareonearth.com> writes:
> I'm having difficulty dealing with null text/varchar fields. I need
> to be able to interpret null values as the null string '' for the
> purposes on concatenation.
> This one gave me "ERROR: copyObject: don't know how to copy 704":
> SELECT ( case field_one when 'string' then 'other' else 'third' end)
> from t1;
That is a parsing bug that I have just fixed; should be OK in the next
6.5 snapshot.
There is a better way, namely the COALESCE function, which is really
a shorthand form of CASE:
COALESCE(arg1,arg2,...,argN)
This gives you the first of the arg values that isn't NULL. So
COALESCE(field1, '')
will substitute '' for NULL values.
Don't ask me why the SQL standards committee chose to call it COALESCE.
Doesn't make sense to me either ;-)
regards, tom lane
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, gwaldron@wareonearth.com, pgsql-sql@hub.org
Subject: Re: [SQL] Trouble with null text fields!
In-Reply-To: <26721.924457892@sss.pgh.pa.us>
References: <199904140300.XAA22576@hub.org> <26721.924457892@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