Re: NULL concatenation

Поиск
Список
Период
Сортировка
От George Neuner
Тема Re: NULL concatenation
Дата
Msg-id bjtajb9dhgl9arm6pe1v9csi6s97el53li@4ax.com
обсуждение исходный текст
Ответ на NULL concatenation  (Sridhar N Bamandlapally <sridhar.bn1@gmail.com>)
Список pgsql-general
On Fri, 13 May 2016 08:45:46 +0530, Sridhar N Bamandlapally
<sridhar.bn1@gmail.com> wrote:

>we need simple concatenation of all variables(which values may come NULL or
>valid-values based on functional process),
>
>coalesce is different functionality

As Pavel suggested, concat will work, but it swallows NULLs leaving no
trace of them in the output.  Using coalesce *with* concat lets you
decide what a NULL will look like:

e.g.,

>> do $$
>> declare
>>     txt1 text := 'ABCD';
>>     txt2 text := NULL;
>>     txt3 text := 'EFGH';
>>     txt text := NULL;
>> begin

  txt := coalesce( txt1, '' )
        || coalesce( txt2, 'txt2 was null' )
        || coalesce( txt3, '<null>') ;

>>     raise notice '%', txt;
>> end$$ language plpgsql;

George

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

Предыдущее
От: JingYuan Chen
Дата:
Сообщение: Share my experience and Thank you !
Следующее
От: Arthur Silva
Дата:
Сообщение: Re: Share my experience and Thank you !