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

From Grzegorz Jaśkiewicz
Subject Re: Sorting by an arbitrary criterion
Date
Msg-id 2f4958ff0907090935r32f44227m13a158c6d2fcc5b2@mail.gmail.com
Whole thread Raw
In response to Sorting by an arbitrary criterion  (Craig James <craig_james@emolecules.com>)
Responses Re: Sorting by an arbitrary criterion
List pgsql-performance
On Thu, Jul 9, 2009 at 5:26 PM, Craig James<craig_james@emolecules.com> 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'
>  5 => 'h'
>
> So when I get done, the sort order should be 2,3,5,4,1.
>
> I could create a temporary table with the category-to-key mapping, but is
> there any way to do this in a single SQL statement?
>

you can create translation table, join it, and sort by its key.


--
GJ

pgsql-performance by date:

Previous
From: Craig James
Date:
Subject: Sorting by an arbitrary criterion
Next
From: Robin Houston
Date:
Subject: Huge difference in query performance between 8.3 and 8.4 (possibly)