CASE

From: "James Taylor" <jtx(at)hatesville(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: CASE
Date: 2003-05-19 06:59:46
Message-ID: 002201c31dd4$3f34c100$0000fea9@theplague
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi everyone, I'm trying to figure out how to get CASE working in a sum
aggregate function. Pretty simple query:

select sum(numbers) from lists where uid=1;

It's possible that there may be 0 rows where uid == 1. Instead of
returning 1 blank row, I want it to return '0'. So, I tried this:

select case(sum(numbers)) when null then 0 else sum(numbers) end from
list_results;

That... Doesn't work. Any suggestions on how to do this and where I can
find some decent information on use of CASE?

Responses

  • Re: CASE at 2003-05-19 22:49:21 from Stephan Szabo
  • Re: CASE at 2003-05-19 23:24:49 from Rod Taylor
  • Re: CASE at 2003-05-19 23:52:41 from Manfred Koizar
  • Re: CASE at 2003-05-20 00:17:30 from Tom Lane

Browse pgsql-sql by date

  From Date Subject
Next Message Dan S 2003-05-19 11:39:10 Referencing a column from another table in a different database with a foreign key constraint.
Previous Message Rajendran 2003-05-19 05:23:06 Inquiry From Form [pgsql]