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

From Grzegorz Jaśkiewicz
Subject Re: Sorting by an arbitrary criterion
Date
Msg-id [email protected]
Whole thread Raw
In response to Re: Sorting by an arbitrary criterion  (Tom Lane <[email protected]>)
List pgsql-performance
2009/7/9 Tom Lane <[email protected]>:
> =?UTF-8?Q?Grzegorz_Ja=C5=9Bkiewicz?= <[email protected]> writes:
>> On Thu, Jul 9, 2009 at 5:26 PM, Craig James<[email protected]> 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:
>
>> you can create translation table, join it, and sort by its key.
>
> Much easier to
>        ORDER BY CASE category WHEN 'z' THEN 1 WHEN 'a' THEN 2 ... END
>
> Actually, consider putting the CASE into a function and doing
>        ORDER BY sort_order(category)

I suppose table is handy, when you have a lot of items as keys...



--
GJ

pgsql-performance by date:

Previous
From: "Hartman, Matthew"
Date:
Subject: Re: Sorting by an arbitrary criterion
Next
From: "Albe Laurenz"
Date:
Subject: Re: embedded sql regression from 8.2.4 to 8.3.7