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

From: Rosser Schwarz <rosser(dot)schwarz(at)gmail(dot)com>
To: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
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-23 21:04:37
Message-ID: 37d451f70912231304i3515e575x69b31638962739a6@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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. Instead, try:

SELECT
COALESCE(t_number::text, '') ||
COALESCE(t_string::text, '') ||
COALESCE(t_date::text, '') ||
COALESCE(t_boolean::text, '') ||
...

rls

--
:wq

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Craig Ringer 2009-12-24 03:08:04 Re: Using || operator to fold multiple columns into one
Previous Message Pavel Stehule 2009-12-23 18:53:55 Re: short-cutting if sum()>constant