Search Postgresql Archives

Re: NULL concatenation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 13 May 2016 08:45:46 +0530, Sridhar N Bamandlapally
<sridhar.bn1@xxxxxxxxx> 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



-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux