Re: coalesce and aggregate functions - Mailing list pgsql-hackers

From Gregory Stark
Subject Re: coalesce and aggregate functions
Date
Msg-id 87slfljff8.fsf@enterprisedb.com
Whole thread Raw
In response to coalesce and aggregate functions  (Patrick Welche <prlw1@newn.cam.ac.uk>)
List pgsql-hackers
"Patrick Welche" <prlw1@newn.cam.ac.uk> writes:

> Is this a bug, or don't I understand coalesce()?
>
> select coalesce(0,sum(b)) from test where a=2;  -- 0 !
>
> So when I use coalesce() with sum(), I always get the constant. I would
> have expected it only in the case where sum() returns null..

Coalesce will return the first argument if it's not null. 
You may be thinking about the arguments in reverse order?

--  Gregory Stark EnterpriseDB          http://www.enterprisedb.com


pgsql-hackers by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Re: coalesce and aggregate functions
Next
From: "Kevin Grittner"
Date:
Subject: Re: coalesce and aggregate functions