Re: Sorting by an arbitrary criterion - Mailing list pgsql-performance

From Hartman, Matthew
Subject Re: Sorting by an arbitrary criterion
Date
Msg-id 366642367C5B354197A1E0D27BC175BD02259884@KGHMAIL.KGH.ON.CA
Whole thread Raw
In response to Re: Sorting by an arbitrary criterion  (hubert depesz lubaczewski <depesz@depesz.com>)
List pgsql-performance
> On Thu, Jul 09, 2009 at 09:26:42AM -0700, Craig James wrote:
> You can do it like this:
> select c.*
> from categories c, ( values (1, 'z'), (2, 'a'), (3, 'b'), (4, 'w'),
(5,
> 'h') ) as o (id, ordering) on c.id = o.id
> order by o.ordering

Another option would be:

select c.*
from categories c
order by case(c.category) when 1 then 'z' when 2 then 'a' then 3 then
'b' when 4 then 'w' when 5 then 'h' end;

Matthew Hartman
Programmer/Analyst
Information Management, ICP
Kingston General Hospital


pgsql-performance by date:

Previous
From: hubert depesz lubaczewski
Date:
Subject: Re: Sorting by an arbitrary criterion
Next
From: Grzegorz Jaśkiewicz
Date:
Subject: Re: Sorting by an arbitrary criterion