Re: concatenating with NULLs

From: Bosco Rama <postgres(at)boscorama(dot)com>
To: Seb <spluque(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: concatenating with NULLs
Date: 2011-04-25 22:24:59
Message-ID: 4DB5F4BB.3060304@boscorama.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Seb wrote:
> A query such as:
>
> SELECT 'a' || 'b' || NULL;
>
> returns a NULL. How can I ensure I get 'ab' in the result? I'm trying
> to concatenate columns and one of them might have NULL values, which I
> simply want to ignore.

COALESCE is your friend:
select 'a' || 'b' || COALESCE(columnName, '');

HTH

Bosco.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Glen Parker 2011-04-25 22:28:54 Re: concatenating with NULLs
Previous Message Seb 2011-04-25 21:13:03 concatenating with NULLs