Search Postgresql Archives

Re: how to return field based on field= NULL or not

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Aug 23, 2009 at 11:43 PM, Juan Backson<juanbackson@xxxxxxxxx> wrote:
> Hi,
>
> Thank you for your help.
>
> What I want to dos is as follows:
>
> SELECT COALESCE(fieldA::text,fieldB||fieldC||fieldD) from ring where
> group_id = 1
>
> if fieldB is NULL, i will want it to return fieldC|| fieldD
> if fieldB and fieldC is null, I want it to return fieldD.
>
> Basically, fieldD is always going to have data, but fieldB and fieldC can be
> NULL.
>
> How can I revise the query to meet that purpose?

Just coalesce them all to '' and cat them:
... coalesce(a,'')||coalesce(b,'')||coalesce(c,'')||d ...

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux