X-Original-To: pgsql-sql@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id 06A9C925BEB for ; Fri, 30 May 2003 11:47:07 -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 25175-03 for ; Fri, 30 May 2003 11:47:05 -0400 (EDT) Received: from web20415.mail.yahoo.com (web20403.mail.yahoo.com [66.163.169.91]) by developer.postgresql.org (Postfix) with SMTP id D67A0925B2B for ; Fri, 30 May 2003 11:47:04 -0400 (EDT) Message-ID: <20030530154703.37238.qmail@web20415.mail.yahoo.com> Received: from [65.207.234.18] by web20403.mail.yahoo.com via HTTP; Fri, 30 May 2003 08:47:03 PDT Date: Fri, 30 May 2003 08:47:03 -0700 (PDT) From: C F Subject: SQL Help To: pgsql-sql@postgresql.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-757754959-1054309623=:37106" X-Virus-Scanned: by amavisd-new X-Archive-Number: 200305/568 X-Sequence-Number: 13733 --0-757754959-1054309623=:37106 Content-Type: text/plain; charset=us-ascii Hello, I already tried this same basic question with no response.... maybe I was too wordy. So here it is simplified.... what's the best way to write this query? I'm open to using stored procedures, but even then I don't know how I would conditionally populate a resultset (refcursor). Notice that in the first three cases, the expression is the exact same, only the return value is different. This seems inefficient.... select (case when column1 = column2 then column3 end) as alias1, (case when column1 = column2 then column4 end) as alias2, (case when column1 = column2 then column5 end) as alias3, (case when column6 = column7 then column8 end) as alias4 from mytable ; Any ideas? Thanks! --------------------------------- Do you Yahoo!? Free online calendar with sync to Outlook(TM). --0-757754959-1054309623=:37106 Content-Type: text/html; charset=us-ascii
Hello,
I already tried this same basic question with no response....  maybe I was too wordy.  So here it is simplified.... what's the best way to write this query?  I'm open to using stored procedures, but even then I don't know how I would conditionally populate a resultset (refcursor).  Notice that in the first three cases, the expression is the exact same, only the return value is different.  This seems inefficient....
 

select
  (case when column1 = column2 then column3 end) as alias1,
  (case when column1 = column2 then column4 end) as alias2,
  (case when column1 = column2 then column5 end) as alias3,
  (case when column6 = column7 then column8 end) as alias4
from
  mytable
;
Any ideas? 
Thanks!


Do you Yahoo!?
Free online calendar with sync to Outlook(TM). --0-757754959-1054309623=:37106--