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

From: Juan Backson <juanbackson(at)gmail(dot)com>
To: Wojtek <foo(at)twine(dot)pl>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: how to return field based on field= NULL or not
Date: 2009-08-24 05:43:42
Message-ID: 27c25bc40908232243i357f8669m8467a8f7bb9eb7a4@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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?

Thanks,
JB

On Mon, Aug 24, 2009 at 11:55 AM, Wojtek <foo(at)twine(dot)pl> wrote:

> Hi,
>
> I assume one field will always be NULL and one will always has data in it.
>
> select coalesce(fieldA, fieldB) from table
>
> Regards,
> foo
>
>
> Juan Backson wrote:
>
>> Hi,
>>
>> In my table, I have fieldA and fieldB. At any point in time, only one of
>> these fields can have data in it. The other is NULL.
>>
>> Instead of "select fieldA, fieldB from table", I want it to return either
>> fieldA or fieldB depends on whether it is NULL or not.
>>
>> The reason is because I want to use "select
>> array_to_string(array_accum(field A or field B) ,',') from table.
>>
>> Is it possible to do it that way?
>>
>> Thanks,
>> JB
>>
>
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2009-08-24 05:50:10 Re: how to return field based on field= NULL or not
Previous Message Kushal Vaghani 2009-08-24 05:25:40 Install from Source On Windows - University of Sydney Research