Re: Cast question (NULL -> NUMERIC)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Henry House <hajhouse(at)houseag(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Cast question (NULL -> NUMERIC)
Date: 2001-07-13 21:11:25
Message-ID: 18652.995058685@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox
Thread:
Lists: pgsql-novice

Henry House <hajhouse(at)houseag(dot)com> writes:
> the balance forward of the amount column for the user-suplied date correcly
> unless the user supplies a $startdate such that no culumns are being added.
> In this case NULL is returned.

Yeah, for some unfathomable reason SQL92 defines SUM() of no rows to
return NULL, rather than zero as any mathematician would say it should.

Use COALESCE(SUM(...), 0) to replace the null result by 0.

regards, tom lane

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Todd T. Fries 2001-07-13 22:03:49 Re: Serial field
Previous Message Henry House 2001-07-13 18:53:38 Cast question (NULL -> NUMERIC)