Re: [PERFORM] Sorting by an arbitrary criterion

2009-07-09 Thread Grzegorz Jaśkiewicz
2009/7/9 Tom Lane : > =?UTF-8?Q?Grzegorz_Ja=C5=9Bkiewicz?= writes: >> On Thu, Jul 9, 2009 at 5:26 PM, Craig James >> wrote: >>> Suppose I have a large table with a small-cardinality CATEGORY column (say, >>> categories 1..5).  I need to sort by an arbitrary (i.e. user-specified) >>> mapping of CA

Re: [PERFORM] Sorting by an arbitrary criterion

2009-07-09 Thread Hartman, Matthew
> 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

Re: [PERFORM] Sorting by an arbitrary criterion

2009-07-09 Thread hubert depesz lubaczewski
On Thu, Jul 09, 2009 at 09:26:42AM -0700, Craig James wrote: > Suppose I have a large table with a small-cardinality CATEGORY column (say, > categories 1..5). I need to sort by an arbitrary (i.e. user-specified) > mapping of CATEGORY, something like this: > > 1 => 'z' > 2 => 'a' > 3 => 'b' >

Re: [PERFORM] Sorting by an arbitrary criterion

2009-07-09 Thread Alexander Staubo
On Thu, Jul 9, 2009 at 6:26 PM, Craig James wrote: > Suppose I have a large table with a small-cardinality CATEGORY column (say, > categories 1..5).  I need to sort by an arbitrary (i.e. user-specified) > mapping of CATEGORY, something like this: > >  1 => 'z' >  2 => 'a' >  3 => 'b' >  4 => 'w' >

Re: [PERFORM] Sorting by an arbitrary criterion

2009-07-09 Thread Kevin Grittner
Craig James wrote: > Suppose I have a large table with a small-cardinality CATEGORY > column (say, categories 1..5). I need to sort by an arbitrary > (i.e. user-specified) mapping of CATEGORY There was a recent thread discussing ways to do that: http://archives.postgresql.org/pgsql-admin/200

Re: [PERFORM] Sorting by an arbitrary criterion

2009-07-09 Thread Tom Lane
=?UTF-8?Q?Grzegorz_Ja=C5=9Bkiewicz?= writes: > On Thu, Jul 9, 2009 at 5:26 PM, Craig James wrote: >> Suppose I have a large table with a small-cardinality CATEGORY column (say, >> categories 1..5).  I need to sort by an arbitrary (i.e. user-specified) >> mapping of CATEGORY, something like this:

Re: [PERFORM] Sorting by an arbitrary criterion

2009-07-09 Thread Grzegorz Jaśkiewicz
On Thu, Jul 9, 2009 at 5:26 PM, Craig James wrote: > Suppose I have a large table with a small-cardinality CATEGORY column (say, > categories 1..5).  I need to sort by an arbitrary (i.e. user-specified) > mapping of CATEGORY, something like this: > >  1 => 'z' >  2 => 'a' >  3 => 'b' >  4 => 'w' >

[PERFORM] Sorting by an arbitrary criterion

2009-07-09 Thread Craig James
Suppose I have a large table with a small-cardinality CATEGORY column (say, categories 1..5). I need to sort by an arbitrary (i.e. user-specified) mapping of CATEGORY, something like this: 1 => 'z' 2 => 'a' 3 => 'b' 4 => 'w' 5 => 'h' So when I get done, the sort order should be 2,3,5,4,1