Re: CONCAT returns null

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>, pgsql-general(at)postgresql(dot)org
Subject: Re: CONCAT returns null
Date: 2016-02-28 16:21:20
Message-ID: 56D31E80.2070306@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 02/28/2016 02:30 AM, Andreas Kretschmer wrote:
> Sterpu Victor <victor(at)caido(dot)ro> wrote:
>
>> Hello
>>
>> I have this concat:
>> CONCAT(f.nrfo, '/', TO_CHAR(fd1.validfrom, 'YYYY-MM-DD'), f2.nrfo, TO_CHAR
>> (fd7.validfrom, 'YYYY-MM-DD'), DATE(fd5.validto)-DATE(fd1.validfrom))
>> that works fine but when I change to this(I added a ' with '):
>> ARRAY_AGG(CONCAT(f.nrfo, '/', TO_CHAR(fd1.validfrom, 'YYYY-MM-DD'), ' with ',
>> f2.nrfo, TO_CHAR(fd7.validfrom, 'YYYY-MM-DD'), DATE(fd5.validto)-DATE
>> (fd1.validfrom))) AS temp,
>> then concat returns NULL.
>> Why? I tried to add ' with '::VARCHAR and ' with '::TEXT but the result is
>> still NULL.
>>
>> Thank you
>
> NULL concat with a value returns NULL. You can avoid that using
> COALESCE(value, ''), that returns the value, or, if the value NULL, ''.

http://www.postgresql.org/docs/9.5/interactive/functions-string.html
"
concat(str "any" [, str "any" [, ...] ]) text Concatenate the text
representations of all the arguments. NULL arguments are ignored.
"
>
>
> Andreas
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andreas Kretschmer 2016-02-28 16:30:44 Re: CONCAT returns null
Previous Message Aaron Christensen 2016-02-28 14:21:49 Re: Designing tables based on user input and defined values