Re: A slow query - Help please? - Mailing list pgsql-general

From Gurjeet Singh
Subject Re: A slow query - Help please?
Date
Msg-id 65937bea0606190500n1718ad1v744dab59e74f3892@mail.gmail.com
Whole thread Raw
In response to Re: A slow query - Help please?  (Alban Hertroys <alban@magproductions.nl>)
List pgsql-general
Hubert said 'do "something similar" to this'... The syntax was
incorrect for sure.

If you wish to be able to do ORDER BY and LIMIT in UNION queries, you
need to make them sub-queries "something similar" to this:

select * from
(
select * from (select * from only table_a  order by number desc limit 25) as A
union
select * from (select * from only table_b  order by number desc limit 25) as B
union
select * from (select * from only table_c  order by number desc limit 25) as C
) x
order by number desc limit 25;

    Again, this query and the syntax is totally untested (I don't have
access to a PG right now); and I don't know much about the history of
this thread!!! But I think it will allow you to do a LIMIT 25 alright.

> And of course 'select *' isn't going to work in the subqueries, the base
> table contains less columns than the inherited tables.

    I don't think you have much of an option in that case...

pgsql-general by date:

Previous
From: "Florian G. Pflug"
Date:
Subject: Re: Adding foreign key constraints without integrity check?
Next
From: Alban Hertroys
Date:
Subject: Re: A slow query - Help please?