Simulating MySQL's ORDER BY FIELD() in Postgresql

Posted by Peer Allan on Stack Overflow See other posts from Stack Overflow or by Peer Allan
Published on 2009-08-21T01:07:03Z Indexed on 2010/04/13 10:02 UTC
Read the original article Hit count: 423

Filed under:
|
|

Hello all,

Just trying out Postgresql for the first time, coming from MySQL. In our Rails application we have a couple of locations with SQL like so:

SELECT * FROM `currency_codes` ORDER BY FIELD(code, 'GBP', 'EUR', 'BBD', 'AUD', 'CAD', 'USD') DESC, name ASC

It didn't take long to discover that this is not supported/allowed in Postgresql.

Does anyone know how to simulate this behaviour in Postgres or do we have to pull to sorting out into the code?

Thanks

Peer

© Stack Overflow or respective owner

Related posts about postgresql

Related posts about mysql