Re: or function

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "A(dot) R(dot) Van Hook" <hook(at)lake-lotawana(dot)mo(dot)us>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: or function
Date: 2006-12-30 18:11:36
Message-ID: 13471.1167502296@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"A. R. Van Hook" <hook(at)lake-lotawana(dot)mo(dot)us> 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

In response to

  • or function at 2006-12-30 17:43:01 from A. R. Van Hook

Browse pgsql-sql by date

  From Date Subject
Next Message ramachandra.bhaskaram 2007-01-03 09:35:47 [SQL NOTIFY Help] sending NOTIFY to the external program
Previous Message chester c young 2006-12-30 18:10:38 Re: or function