| From: | "Hartman, Matthew" <Matthew(dot)Hartman(at)krcc(dot)on(dot)ca> |
|---|---|
| To: | <depesz(at)depesz(dot)com>, "Craig James" <craig_james(at)emolecules(dot)com> |
| Cc: | <pgsql-performance(at)postgresql(dot)org> |
| Subject: | Re: Sorting by an arbitrary criterion |
| Date: | 2009-07-09 18:13:52 |
| Message-ID: | 366642367C5B354197A1E0D27BC175BD02259884@KGHMAIL.KGH.ON.CA |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Grzegorz Jaśkiewicz | 2009-07-09 20:25:21 | Re: Sorting by an arbitrary criterion |
| Previous Message | hubert depesz lubaczewski | 2009-07-09 18:11:09 | Re: Sorting by an arbitrary criterion |