Re: Using || operator to fold multiple columns into one

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: Rosser Schwarz <rosser(dot)schwarz(at)gmail(dot)com>
Cc: Bryce Nesbitt <bryce2(at)obviously(dot)com>, sql pgsql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Using || operator to fold multiple columns into one
Date: 2009-12-24 03:08:04
Message-ID: 4B32DB14.6080308@postnewspapers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On 24/12/2009 5:04 AM, Rosser Schwarz wrote:
> On Wed, Dec 23, 2009 at 1:44 AM, Craig Ringer
> <craig(at)postnewspapers(dot)com(dot)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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Mina Waheeb 2009-12-28 16:57:18 Invitation to connect on LinkedIn
Previous Message Rosser Schwarz 2009-12-23 21:04:37 Re: Using || operator to fold multiple columns into one