Re: differnt behaviour of NULL in an aggregate and with an operator

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: Willy-Bas Loos <willybas(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: differnt behaviour of NULL in an aggregate and with an operator
Date: 2008-08-12 08:43:14
Message-ID: 48A14D22.1080904@postnewspapers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Willy-Bas Loos wrote:
> Hi,
>
> Why is it that
> SELECT 1+null
> evaluates to NULL, but
> SELECT sum(foo) FROM (VALUES(1), (NULL)) AS v(foo)
> evaluates to 1 ?

SUM(x) ignores null input, like COUNT(x) etc. It's the sum of all
non-null instances of x.

There's some useful explanation of the various NULL handling of
aggregates here:

http://www.postgresql.org/docs/8.3/static/sql-createaggregate.html

though I'm not sure how well it applies to the built-in aggregates.

--
Craig Ringer

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Cyril SCETBON 2008-08-12 08:51:47 Re: Checkpoints writes
Previous Message Willy-Bas Loos 2008-08-12 08:29:57 differnt behaviour of NULL in an aggregate and with an operator