Re: [SQL] Trouble with null text fields! - Mailing list pgsql-sql

From Tom Lane
Subject Re: [SQL] Trouble with null text fields!
Date
Msg-id 26721.924457892@sss.pgh.pa.us
Whole thread Raw
List pgsql-sql
"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.  SoCOALESCE(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


pgsql-sql by date:

Previous
From: Daniele Orlandi
Date:
Subject: PL/TCL and NULL values
Next
From: Andy Lewis
Date:
Subject: Case insensitive searchs