pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: James Taylor <jtx@hatesville.com>
To: pgsql-sql@postgresql.org
Subject: CASE
Date: Sun, 18 May 2003 23:59:46 -0700
Message-ID: <002201c31dd4$3f34c100$0000fea9@theplague> (raw)

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?






view thread (20+ messages)  latest in thread

Message-ID: <002201c31dd4$3f34c100$0000fea9@theplague>
Permalink:  ../002201c31dd4$3f34c100$0000fea9@theplague/
Also on:    postgresql.org/message-id/002201c31dd4$3f34c100$0000fea9@theplague

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: jtx@hatesville.com
  Subject: Re: CASE
  In-Reply-To: <002201c31dd4$3f34c100$0000fea9@theplague>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox