pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephan Szabo <sszabo@megazone23.bigpanda.com>
To: James Taylor <jtx@hatesville.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: CASE
Date: Mon, 19 May 2003 15:49:21 -0700 (PDT)
Message-ID: <20030519154658.Q43251-100000@megazone23.bigpanda.com> (raw)
In-Reply-To: <002201c31dd4$3f34c100$0000fea9@theplague>


On Sun, 18 May 2003, James Taylor wrote:

> 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;

I believe the case would be:

case when sum(numbers) is null then 0 else sum(numbers) end

It's more like the ternary operator than a switch statement.





view thread (20+ messages)  latest in thread

Message-ID: <20030519154658.Q43251-100000@megazone23.bigpanda.com>
Permalink:  ../20030519154658.Q43251-100000@megazone23.bigpanda.com/
Also on:    postgresql.org/message-id/20030519154658.Q43251-100000@megazone23.bigpanda.com

 · 

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: sszabo@megazone23.bigpanda.com, jtx@hatesville.com
  Subject: Re: CASE
  In-Reply-To: <20030519154658.Q43251-100000@megazone23.bigpanda.com>

* 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