I have an operation which gives me a list of IDs and some score related to these IDs. Then I need query the database and sort rows using the data above.
I tried something like (I'm using PostgreSQL):
SELECT * FROM sometable
LEFT OUTER JOIN (VALUES (629, 3), (624, 1)) /* Here is my data */
AS x(id, ordering)
USING (id)
WHERE some_column_id=1
ORDER BY x.ordering;
But for ~10000 rows it runs about 15sec on my machine. Is there a better way to sort my table using a previously calculated data?
idand run the query.