X-Original-To: pgsql-sql@postgresql.org Received: from localhost (unknown [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id 6E3269260BE for ; Mon, 19 May 2003 18:36:40 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193:10024]) (amavisd-new) with ESMTP id 47162-02 for ; Mon, 19 May 2003 18:36:36 -0400 (EDT) Received: from smtp801.mail.sc5.yahoo.com (smtp801.mail.sc5.yahoo.com [66.163.168.180]) by developer.postgresql.org (Postfix) with SMTP id EA60A925547 for ; Mon, 19 May 2003 02:59:38 -0400 (EDT) Received: from adsl-67-114-255-130.dsl.lsan03.pacbell.net (HELO theplague) (heavenstrash@sbcglobal.net@67.114.255.130 with login) by smtp-sbc-v1.mail.vip.sc5.yahoo.com with SMTP; 19 May 2003 06:59:37 -0000 Reply-To: From: "James Taylor" To: Subject: CASE Date: Sun, 18 May 2003 23:59:46 -0700 Message-ID: <002201c31dd4$3f34c100$0000fea9@theplague> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2616 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Importance: Normal X-Virus-Scanned: by amavisd-new X-Archive-Number: 200305/370 X-Sequence-Number: 13535 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?