Re: Sorted union - Mailing list pgsql-performance

From Merlin Moncure
Subject Re: Sorted union
Date
Msg-id 6EE64EF3AB31D5448D0007DD34EEB3417DD78D@Herge.rcsinc.local
Whole thread Raw
In response to Sorted union  (Scott Lamb <slamb@slamb.org>)
Responses Re: Sorted union
List pgsql-performance
>      select    when_stopped as when_happened,
>                1 as order_hint
>      from      transaction t
>      where     '2005-10-25 15:00:00' <= when_stopped
>        and     when_stopped <= '2005-10-26 10:00:00'
>      union all
>      select    when_stopped as when_happened,
>                2 as order_hint
>      from      transaction t
>      where     '2005-10-25 15:00:00' <= when_stopped
>        and     when_stopped <= '2005-10-26 10:00:00'
>      order by  when_happened, order_hint;

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

question: why do you want to flatten the table...is it not easier to
work with as records?

Merlin


pgsql-performance by date:

Previous
From: Qingqing Zhou
Date:
Subject: Re: insert performance for win32
Next
From: Sven Willenberger
Date:
Subject: Function with table%ROWTYPE globbing