Re: [SQL] Trouble with null text fields!

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [SQL] Trouble with null text fields!
Дата
Msg-id 26721.924457892@sss.pgh.pa.us
обсуждение исходный текст
Список 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 по дате отправления:

Предыдущее
От: Daniele Orlandi
Дата:
Сообщение: PL/TCL and NULL values
Следующее
От: Andy Lewis
Дата:
Сообщение: Case insensitive searchs