Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id B15B69FA43C for ; Sat, 30 Dec 2006 14:12:16 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 94406-09 for ; Sat, 30 Dec 2006 14:12:11 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id D686C9FA456 for ; Sat, 30 Dec 2006 14:12:10 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id kBUIBavN013472; Sat, 30 Dec 2006 13:11:37 -0500 (EST) To: "A. R. Van Hook" cc: pgsql-sql@postgresql.org Subject: Re: or function In-reply-to: <4596A525.9050008@lake-lotawana.mo.us> References: <4596A525.9050008@lake-lotawana.mo.us> Comments: In-reply-to "A. R. Van Hook" message dated "Sat, 30 Dec 2006 11:43:01 -0600" Date: Sat, 30 Dec 2006 13:11:36 -0500 Message-ID: <13471.1167502296@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200612/196 X-Sequence-Number: 27152 "A. R. Van Hook" writes: > I have been trying to do an 'or' function such that if a field value is > zero then use 1 as a multiplier: > "select sum((1 | i.count) * s.cost) as COST Bitwise OR will surely not do what you want. I think the most effective solution is probably CASE: select sum(case when i.count = 0 then s.cost else i.count * s.cost end) ... regards, tom lane