Re: Using || operator to fold multiple columns into one - Mailing list pgsql-sql

From Craig Ringer
Subject Re: Using || operator to fold multiple columns into one
Date
Msg-id 4B32DB14.6080308@postnewspapers.com.au
Whole thread Raw
In response to Re: Using || operator to fold multiple columns into one  (Rosser Schwarz <rosser.schwarz@gmail.com>)
Responses Re: Using || operator to fold multiple columns into one  (Bryce Nesbitt <bryce2@obviously.com>)
List pgsql-sql
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


pgsql-sql by date:

Previous
From: Rosser Schwarz
Date:
Subject: Re: Using || operator to fold multiple columns into one
Next
From: Mina Waheeb
Date:
Subject: Invitation to connect on LinkedIn