Re: coalesce and aggregate functions

From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: "Patrick Welche" <prlw1(at)newn(dot)cam(dot)ac(dot)uk>
Cc: <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: coalesce and aggregate functions
Date: 2006-12-12 15:35:07
Message-ID: 87slfljff8.fsf@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


"Patrick Welche" <prlw1(at)newn(dot)cam(dot)ac(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Kevin Grittner 2006-12-12 15:35:26 Re: coalesce and aggregate functions
Previous Message Heikki Linnakangas 2006-12-12 15:33:04 Re: coalesce and aggregate functions