Re: Sorted union - Mailing list pgsql-performance

From Kevin Grittner
Subject Re: Sorted union
Date
Msg-id 436A0C8F0200002500000459@gwmta.wicourts.gov
Whole thread Raw
In response to Sorted union  (Scott Lamb <slamb@slamb.org>)
List pgsql-performance
Just as an FYI, if you want to reassure yourself that the ORDER BY
is being applied as intended, you could do the following:

(
 select 1 as hint, start_time as when [...]
 union all
 select 2 as hint, end_time as when [...]
) order by seq, when

This is ANSI/ISO standard, and works in PostgreSQL (based on
a quick test).


>>> "Merlin Moncure" <merlin.moncure@rcsonline.com>  >>>

hmm, try pushing the union into a subquery...this is better style
because it's kind of ambiguous if the ordering will apply before/after
the union.

select q.when from
(
 select 1 as hint, start_time as when [...]
 union all
 select 2 as hint, end_time as when [...]
) q order by q.seq, when


pgsql-performance by date:

Previous
From: "Magnus Hagander"
Date:
Subject: Re: insert performance for win32
Next
From: "Magnus Hagander"
Date:
Subject: Re: insert performance for win32