Sorting by an arbitrary criterion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
Sent via pgsql-performance mailing list (pgsql-performance@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance

[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux