Re: Union Query Improvement

From: Chris <dmagick(at)gmail(dot)com>
To: Ray Bannon <bannonr(at)comcast(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Union Query Improvement
Date: 2007-02-14 07:25:41
Message-ID: 45D2B975.5020501@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ray Bannon wrote:
> I have a query which is running a bit slowly, and I'm wondering if anyone
> has a design improvement. Basically it's a series of unions as follows:
>
> Select ID, plan_name from table/view
> Where plan_name = 'A'
> And rownum = 1
> UNION
> Select ID, plan_name from table/view
> Where plan_name = 'B'
> And rownum = 1
> UNION
> Select ID, plan_name from table/view
> Where plan_name = 'C'
> And rownum = 1
> UNION
>
> Ad infinitum for about 100 iterations.

I'm sure I'm missing something but wouldn't this give the same results:

select id, plan_name from table where rownum=1 and plan_name in ('A',
'B', 'C');

?

Or do the rownum's change later on?

--
Postgresql & php tutorials
http://www.designmagick.com/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Chris 2007-02-14 07:29:12 Re: Slony Replication problem
Previous Message Tom Lane 2007-02-14 07:23:09 Re: Infinite loop in transformExpr()