Re: CASE

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: jtx(at)hatesville(dot)com
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: CASE
Date: 2003-05-20 00:17:30
Message-ID: 24789.1053389850@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"James Taylor" <jtx(at)hatesville(dot)com> writes:
> select case(sum(numbers)) when null then 0 else sum(numbers) end from
> list_results;

The reason the above doesn't work is that it expands to
CASE WHEN sum(numbers) = null THEN ...
which always fails ("= null" does not mean "is null").

Easier would be SELECT COALESCE(sum(numbers), 0) FROM list_results

regards, tom lane

In response to

  • CASE at 2003-05-19 06:59:46 from James Taylor

Browse pgsql-sql by date

  From Date Subject
Next Message Dean Gibson (DB Administrator) 2003-05-20 00:28:05 Re: Testing castability of text to numeric
Previous Message Manfred Koizar 2003-05-19 23:52:41 Re: CASE