"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