Re: coalesce seems to give strange results

From: Thom Brown <thombrown(at)gmail(dot)com>
To: Richard Yen <richyen(at)iparadigms(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: coalesce seems to give strange results
Date: 2010-07-15 00:12:07
Message-ID: AANLkTimgjcuOgVLhNYwn7YU-IFwsBF4HcnTCvnN-q5I_@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 15 July 2010 00:52, Richard Yen <richyen(at)iparadigms(dot)com> wrote:
> Hi everyone,
>
> Looks like I'm encountering some quirks with coalesce()...
>
>> postgres=# select coalesce(null,0);
>>  coalesce
>> ----------
>>         0
>> (1 row)
>>
>> postgres=# SELECT COALESCE(ROUND(EXTRACT(epoch FROM now()-query_start)),0) FROM pg_stat_activity WHERE current_query = '<IDLE> in transaction';
>>  coalesce
>> ----------
>> (0 rows)
>>
>> postgres=# select version();
>>                                                       version
>> -------------------------------------------------------------------------------------------------------------------
>>  PostgreSQL 8.4.2 on x86_64-unknown-linux-gnu, compiled by GCC gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-44), 64-bit
>> (1 row)
>
> Any ideas?
> --Richard
> --

I don't see what you mean. The query can't return any rows because
none match the criterion specified. If you'd normally get 0 rows if
using SELECT *, then adding in coalesce isn't going to force a result
as there's nothing to select against.

postgres=# SELECT COALESCE(NULL,0) FROM pg_stat_activity WHERE
current_query = '<IDLE> in transaction'; coalesce
----------
(0 rows)

postgres=# select coalesce(null,0) from pg_database where 1 = 2;
coalesce
----------
(0 rows)

Thom

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard Yen 2010-07-15 00:21:18 Re: coalesce seems to give strange results
Previous Message Richard Yen 2010-07-14 23:52:25 coalesce seems to give strange results