From: | Grzegorz Jaśkiewicz <gryzman(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Craig James <craig_james(at)emolecules(dot)com>, pgsql-performance(at)postgresql(dot)org |
Subject: | Re: Sorting by an arbitrary criterion |
Date: | 2009-07-09 20:25:21 |
Message-ID: | 2f4958ff0907091325v3f21dd96y7d8c0ae93513f052@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
2009/7/9 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
> =?UTF-8?Q?Grzegorz_Ja=C5=9Bkiewicz?= <gryzman(at)gmail(dot)com> writes:
>> On Thu, Jul 9, 2009 at 5:26 PM, Craig James<craig_james(at)emolecules(dot)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:
>
>> 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
From | Date | Subject | |
---|---|---|---|
Next Message | Alex | 2009-07-09 21:34:01 | Poor query performance |
Previous Message | Hartman, Matthew | 2009-07-09 18:13:52 | Re: Sorting by an arbitrary criterion |