Skip site navigation (1) Skip section navigation (2)

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: (view raw or flat)
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


pgsql-novice by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2015 The PostgreSQL Global Development Group