From: Tom Lane <tgl@sss.pgh.pa.us>
To: Michael Richards <miker@scifair.acadiau.ca>
Cc: pgsql-sql@postgreSQL.org
Cc: hackers@postgreSQL.org
Subject: Re: Counting bool flags in a complex query
Date: Fri, 06 Oct 2000 01:01:47 -0400
Message-ID: <24511.970808507@sss.pgh.pa.us> (raw)
In-Reply-To: <Pine.BSF.4.10.9907160447220.38362-100000@scifair.acadiau.ca>
References: <Pine.BSF.4.10.9907160447220.38362-100000@scifair.acadiau.ca>
Quite awhile ago, Michael Richards <miker@scifair.acadiau.ca> wrote:
> It looks like the order by is only being applied to the original select,
> not the unioned select. Some authority should check on it, but by thought
> it that a union does not necessarily maintain the order, so the entire
> select should be applied to the order.
Just FYI, I have committed code for 7.1 that allows ORDER BY to work
correctly for a UNION'd query. A limitation is that you can only do
ordering on columns that are outputs of the UNION:
regression=# select q1 from int8_tbl union select q2 from int8_tbl order by 1;
q1
-------------------
-4567890123456789
123
456
4567890123456789
(4 rows)
regression=# select q1 from int8_tbl union select q2 from int8_tbl order by int8_tbl.q1+1;
ERROR: ORDER BY on a UNION/INTERSECT/EXCEPT result must be on one of the result columns
In the general case of an arbitrary ORDER BY expression, it's not clear
how to transpose it into each UNION source select anyway. It could
be made to work for expressions using only the output columns, but since
ORDER BY expressions are not standard SQL I'm not in a big hurry to make
that happen...
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, miker@scifair.acadiau.ca, hackers@postgreSQL.org
Subject: Re: Counting bool flags in a complex query
In-Reply-To: <24511.970808507@sss.pgh.pa.us>
References: <Pine.BSF.4.10.9907160447220.38362-100000@scifair.acadiau.ca> <24511.970808507@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox