Re: ORDER BY

From: Chris Mulcahy <pgsql(at)cmulcahy(dot)com>
To: George Pavlov <gpavlov(at)mynewplace(dot)com>
Cc: Alexander Staubo <alex(at)purefiction(dot)net>, MicroUser <a(dot)shafar(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: ORDER BY
Date: 2006-11-15 23:53:02
Message-ID: 1163634782.29042.2.camel@gentoobox
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 2006-11-15 at 14:59 -0800, George Pavlov wrote:
Alas, this suggestion is wrong on two counts: (a) UNION expects a single
> ORDER BY that applies to the whole recordset and which has to come at
> the end; (b) UNION re-sorts anyway (it needs to eliminate the dupes)
--
> maybe you are thinking UNION ALL? So, to follow your advice he may
want
> a query like this, although it seems quite silly and there still isn't
> an ironclad guarantee re. the final result sorting:
>
> select * from
> (select * from foo where name != 'Other' order by name) x
> union all
> select * from foo where name = 'Other'
>
>

Here ya go.

select 1 SortCol, * from foo where name != 'Other'
UNION ALL
select 2 SortCol, * from foo where name = 'Other'
order by SortCol;

In response to

Responses

  • Re: ORDER BY at 2006-11-21 09:13:41 from Paefgen, Peter (LDS)

Browse pgsql-general by date

  From Date Subject
Next Message Ed L. 2006-11-16 00:13:08 Re: Transaction id wraparound problem
Previous Message Martin Gainty 2006-11-15 23:35:11 Re: automating backups with windows scheduled tasks and pg_dumpall