Re: SQL Help

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: C F <tacnaboyz(at)yahoo(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: SQL Help
Date: 2003-05-30 16:30:40
Message-ID: 20030530163040.GA22409@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Fri, May 30, 2003 at 08:47:03 -0700,
C F <tacnaboyz(at)yahoo(dot)com> 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.

In response to

  • SQL Help at 2003-05-30 15:47:03 from C F

Browse pgsql-sql by date

  From Date Subject
Next Message Josh Berkus 2003-05-30 16:37:12 Re: SQL Help
Previous Message David Klugmann 2003-05-30 16:02:07 SELECT statement within libpq