pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@commandprompt.com>
To: Neil Harkins <nharkins@well.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: concatenation with a null column (using ||) nulls the result?
Date: Mon, 10 Apr 2006 17:55:56 -0400
Message-ID: <20060410215556.GB5856@surnet.cl> (raw)
In-Reply-To: <Pine.SOL.4.10.10604101430250.2779-100000@well.com>
References: <Pine.SOL.4.10.10604101430250.2779-100000@well.com>

Neil Harkins wrote:

> Note: The cabinets_description for the "548-4th-Cab1" row is " ", 
> not NULL, hence it being displayed. Is this standard SQL behavior? 

Yes; something || NULL yields NULL.  If you want NULL to behave as ""
for the purpose of the concatenation, try

SELECT cabinets_name || ' - ' || COALESCE(cabinets_description, '') AS concat 
FROM cabinets WHERE cabinets_datacenters = 2;

I'm assuming cabinets_name is NOT NULL, so it doesn't need COALESCE.

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support



view thread (5+ messages)  latest in thread

Message-ID: <20060410215556.GB5856@surnet.cl>
Permalink:  ../20060410215556.GB5856@surnet.cl/
Also on:    postgresql.org/message-id/20060410215556.GB5856@surnet.cl

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: alvherre@commandprompt.com, nharkins@well.com
  Subject: Re: concatenation with a null column (using ||) nulls the result?
  In-Reply-To: <20060410215556.GB5856@surnet.cl>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox