Thread: Re: [SQL] Trouble with null text fields!

Re: [SQL] Trouble with null text fields!

From
Tom Lane
Date:
"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