Re: [HACKERS] NULL concatenation

From: Sridhar N Bamandlapally <sridhar(dot)bn1(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PG-General Mailing List <pgsql-general(at)postgresql(dot)org>, PostgreSQL-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] NULL concatenation
Date: 2016-05-12 08:57:22
Message-ID: CAGuFTBVKmcFBV9gXaR-0qKsam4GP_GA4MsyBV_YZwaQwmYzWmg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Thanks Pavel

Great !!

I was thinking both || and CANCAT does same

Thanks again

-
Sridhar
OpenText

On Thu, May 12, 2016 at 2:22 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
wrote:

> Hi
>
> 2016-05-12 10:47 GMT+02:00 Sridhar N Bamandlapally <sridhar(dot)bn1(at)gmail(dot)com>
> :
>
>> Hi
>>
>> In migration, am facing issue with NULL concatenation in plpgsql,
>> by concatenating NULL between any where/position to Text / Varchar, the
>> total string result is setting value to NULL
>>
>>
>> *In Oracle:*
>>
>> declare
>> txt1 VARCHAR2(100) := 'ABCD';
>> txt2 VARCHAR2(100) := NULL;
>> txt3 VARCHAR2(100) := 'EFGH';
>> txt VARCHAR2(100) := NULL;
>> begin
>> txt:= txt1 || txt2 || txt3;
>> dbms_output.put_line (txt);
>> end;
>> /
>>
>> abcdefgh *===>return value*
>>
>>
>>
>> *In Postgres*
>>
>> do $$
>> declare
>> txt1 text := 'ABCD';
>> txt2 text := NULL;
>> txt3 text := 'EFGH';
>> txt text := NULL;
>> begin
>> txt:= txt1 || txt2 || txt3;
>> raise notice '%', txt;
>> end$$ language plpgsql;
>>
>> NOTICE: <NULL> *===> return value*
>>
>>
>> SQL-Server also does same like Oracle
>>
>> Is there any way alternate we have for same behavior in PostgreSQL
>>
>
> use function concat
> http://www.postgresql.org/docs/9.5/static/functions-string.html
>
> postgres=# select concat('AHOJ', NULL,'XXX');
> concat
> ---------
> AHOJXXX
> (1 row)
>
> Regards
>
> Pavel
>
>
>> Please
>>
>> Thanks
>> Sridhar
>> OpenText
>>
>>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message sangeetha 2016-05-12 08:57:30 Alternate or Optimization for with hold cursor
Previous Message Tim Clarke 2016-05-12 08:53:52 Re: NULL concatenation

Browse pgsql-hackers by date

  From Date Subject
Next Message hari.prasath 2016-05-12 10:00:22 Re: Incremental refresh of materialized view - Patch
Previous Message Amit Langote 2016-05-12 08:55:44 Re: Declarative partitioning