I have a list / array of primary keys, now I need to execute an SQL query to get the records from the table in the same order as in the array. For instance:
| id | text | | 1 | random data 1 | | 2 | random data 2 | | 3 | random data 3 | | 4 | random data 4 |
This request:
select * from sample where id in (2,4,1)
Should return lines:
| 2 | random data 2 | | 4 | random data 4 | | 1 | random data 1 |
What is the best way to do this in PostgreSQL 9.3?
source share