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 55A9A924E17 for ; Fri, 30 May 2003 12:28:26 -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 35377-09 for ; Fri, 30 May 2003 12:28:25 -0400 (EDT) Received: from wolff.to (wolff.to [66.93.249.74]) by developer.postgresql.org (Postfix) with SMTP id 391C1925C54 for ; Fri, 30 May 2003 12:28:25 -0400 (EDT) Received: (qmail 22534 invoked by uid 500); 30 May 2003 16:30:40 -0000 Date: Fri, 30 May 2003 11:30:40 -0500 From: Bruno Wolff III To: C F Cc: pgsql-sql@postgresql.org Subject: Re: SQL Help Message-ID: <20030530163040.GA22409@wolff.to> Mail-Followup-To: C F , pgsql-sql@postgresql.org References: <20030530154703.37238.qmail@web20415.mail.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030530154703.37238.qmail@web20415.mail.yahoo.com> User-Agent: Mutt/1.5.4i X-Virus-Scanned: by amavisd-new X-Archive-Number: 200305/570 X-Sequence-Number: 13735 On Fri, May 30, 2003 at 08:47:03 -0700, C F wrote: > 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 > ; That seems pretty efficient. I wouldn't expect the repeated column1 = column2 tests to add much overhead. Unless there is more to the story this looks to be what you want to do.