Re: NULL concatenation - Mailing list pgsql-general

From George Neuner
Subject Re: NULL concatenation
Date
Msg-id bjtajb9dhgl9arm6pe1v9csi6s97el53li@4ax.com
Whole thread Raw
In response to NULL concatenation  (Sridhar N Bamandlapally <sridhar.bn1@gmail.com>)
List 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 by date:

Previous
From: JingYuan Chen
Date:
Subject: Share my experience and Thank you !
Next
From: Arthur Silva
Date:
Subject: Re: Share my experience and Thank you !