Re: select NULL||'abc' returns empty string (or NULL)

Поиск
Список
Период
Сортировка
От Oliver Elphick
Тема Re: select NULL||'abc' returns empty string (or NULL)
Дата
Msg-id 1014811966.5761.353.camel@linda
обсуждение исходный текст
Ответ на select NULL||'abc' returns empty string (or NULL)  (Holger Marzen <holger@marzen.de>)
Список pgsql-general
On Wed, 2002-02-27 at 11:25, Holger Marzen wrote:
> I suppose that PostgreSQL insists that a NULL value cannot be
> concatenated with a string. Can I cast this somehow? I noticed that
> feature when I did a
>
> select * from tab where col1||col2 ilike '%bla%'
>
> and it did't find rows where one of the columns was NULL. Any ideas for
> workarounds?

Use COALESCE():
select * from tab where coalesce(col1,'') | coalesce(col2,'') ilike
'%bla%'

--
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C

     "If we confess our sins, he is faithful and just to
      forgive us our sins, and to cleanse us from all
      unrighteousness."       I John 1:9


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

Предыдущее
От: Martijn van Oosterhout
Дата:
Сообщение: Re: select NULL||'abc' returns empty string (or NULL)
Следующее
От: "Steve SAUTETNER"
Дата:
Сообщение: Re: select NULL||'abc' returns empty string (or NULL)