Re: coalesce and nvl question

Поиск
Список
Период
Сортировка
От Mike Mascari
Тема Re: coalesce and nvl question
Дата
Msg-id 40D9B84A.6020009@mascari.com
обсуждение исходный текст
Ответ на coalesce and nvl question  (Simon Windsor <simon.windsor@cornfield.org.uk>)
Ответы Re: coalesce and nvl question  (Simon Windsor <simon.windsor@cornfield.org.uk>)
Список pgsql-general
Simon Windsor wrote:
> Hi
>
> Is there a standard postgres method of replacing empty strings.
>
> In Oracle, nvl handles nulls and empty strings, as does ifnull() in
> MySQL, but with postgres coalesce only handles null strings.
>
> If, not is the best solution to create a plpgsql function, ie
>
> CREATE FUNCTION isEmpty (character varying, character varying) RETURNS
> character varying

This all depends upon what you mean by handle. Do you want to treat
empty strings as NULL or NULL as empty strings? As you said, you can
treat NULL as empty strings using COALESCE:

SELECT COALESCE(x, '');

You can treat empty strings as NULL

SELECT NULLIF(x, '');

But I'd guess most on this list are wondering why you want to equate
an empty string with NULL, as they have two distinct meanings.
Oracle's treatment of empty strings as NULL is world-renowned for
being insane...

HTH

Mike Mascari



В списке pgsql-general по дате отправления:

Предыдущее
От: alltest1@covad.net
Дата:
Сообщение: Re: simultaneous use of JDBC and libpq
Следующее
От: Simon Windsor
Дата:
Сообщение: Re: coalesce and nvl question