Re: Union Query Improvement

From: Ray Bannon <bannonr(at)comcast(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Union Query Improvement
Date: 2007-02-14 12:43:18
Message-ID: C1F843E6.41D%bannonr@comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

There is only one table/view, it's getting one record for each of the
hundred or so plan ID's that I'm looking for.

On 2/13/07 11:29 PM, in article 45D2BA53(dot)2010100(at)cox(dot)net, "Ron Johnson"
<ron(dot)l(dot)johnson(at)cox(dot)net> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 02/13/07 07:46, 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.
>>
>> Any way to write this more efficiently?
>
> Just out of curiosity: why does your(?) design have 100 tables/views
> with the same (or almost identical) structure?
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
>
> iD8DBQFF0rpTS9HxQb37XmcRAtH5AJ4zz5NPM5rBsNWLrKC+/Md6GhxCNgCfZBHf
> AeMbTRNKp4guK81pGwfU5wc=
> =t9y+
> -----END PGP SIGNATURE-----
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rajarshi Guha 2007-02-14 13:02:44 Re: suggestions on improving a query
Previous Message Robert Grinnell 2007-02-14 12:24:28 Robert Grinnell is out of the office on holiday.