pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Craig Ringer <craig@postnewspapers.com.au>
To: Rosser Schwarz <rosser.schwarz@gmail.com>
Cc: Bryce Nesbitt <bryce2@obviously.com>
Cc: sql pgsql <pgsql-sql@postgresql.org>
Subject: Re: Using || operator to fold multiple columns into one
Date: Thu, 24 Dec 2009 11:08:04 +0800
Message-ID: <4B32DB14.6080308@postnewspapers.com.au> (raw)
In-Reply-To: <37d451f70912231304i3515e575x69b31638962739a6@mail.gmail.com>
References: <4B31D619.1090706@obviously.com>
	<4B31D86D.9030000@postnewspapers.com.au>
	<37d451f70912231304i3515e575x69b31638962739a6@mail.gmail.com>

On 24/12/2009 5:04 AM, Rosser Schwarz wrote:
> On Wed, Dec 23, 2009 at 1:44 AM, Craig Ringer
> <craig@postnewspapers.com.au>  wrote:
>
>> SELECT COALESCE( t_number::text, t:string::text, t_date::text, t_boolean::text) AS value;
>
> Your invocation of COALESCE is incorrect -- it is n-ary, but it
> returns its first non-NULL argument.

Yes. That was the point.

I think we're assuming the OP wants different things. You're assuming 
they're trying to concatenate all fields, where more than one field in a 
given record may be non-null. I'm assuming that all but one field in 
each record will be null, and they want to show the "value" of the 
record - in other words, they're using the record as a sort of union 
type. It looks like that from the example they gave.

--
Craig Ringer



view thread (7+ messages)  latest in thread

Message-ID: <4B32DB14.6080308@postnewspapers.com.au>
Permalink:  ../4B32DB14.6080308@postnewspapers.com.au/
Also on:    postgresql.org/message-id/4B32DB14.6080308@postnewspapers.com.au

 · 

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: craig@postnewspapers.com.au, rosser.schwarz@gmail.com, bryce2@obviously.com
  Subject: Re: Using || operator to fold multiple columns into one
  In-Reply-To: <4B32DB14.6080308@postnewspapers.com.au>

* 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