Sorting by an arbitrary criterion

From: Craig James <craig_james(at)emolecules(dot)com>
To: pgsql-performance(at)postgresql(dot)org
Subject: Sorting by an arbitrary criterion
Date: 2009-07-09 16:26:42
Message-ID: 4A561A42.1080301@emolecules.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

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?

Thanks,
Craig

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Haszlakiewicz, Eric 2009-07-09 16:31:24 embedded sql regression from 8.2.4 to 8.3.7
Previous Message Richard Huxton 2009-07-09 10:52:54 Re: Data caching