SELECT * FROM comments WHERE (comments.id IN (1,3,2,4)) ORDER BY array_position(array[1,3,2,4], comments.id);