Re: ORDER BY

From: Harald Fuchs <hf1110x(at)protecting(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: ORDER BY
Date: 2006-11-16 10:04:15
Message-ID: pupsbn3dy8.fsf@srv.protecting.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

In article <DFDFB8FE-1787-4508-97C4-5FD12357936A(at)purefiction(dot)net>,
Alexander Staubo <alex(at)purefiction(dot)net> writes:

> On Nov 14, 2006, at 23:03 , MicroUser wrote:
>> I need sorted result but the way like this:
>>
>> 0 | Anna
>> 3 | Fernando
>> 2 | Link
>> 1 | Other
>>
>> Record '1 | Other' must by at the end of query result.

> It's not apparent from your example that you want something other
> than a purely lexicographic sort order (after all, "Other" comes
> after "Link", "Fernando" and "Anna", so "order by name" already gets
> you what you want), but I assume that's what you mean.

> If your table is sufficiently small, and the complexity of the actual
> query sufficiently low, prepending an expression sort key might
> suffice:

> select * from foo
> order by (case name when 'Other' then 1 else 0 end), name

Why so complicated?

SELECT whatever FROM foo ORDER BY name = 'Other', name

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2006-11-16 10:08:54 Re: dependency on 32 bit libpq.so on 64 bit Postgres server.
Previous Message Albert 2006-11-16 10:02:13 PostGreSql cannot start after windows update