Notably, you added user_id
as 3rd expression to ORDER BY
to break ties. That's good. But if you want to keep using Row Constructor Comparison, all 3 expressions must share the same sort direction. All ASCENDING
or all DESCENDING
. Else(Else it gets more complex and expensive.
Also) See:
- SQL syntax term for 'WHERE (col1, col2) < (val1, val2)'
- How to form a WHERE condition matching multiple ORDER BY items?
Also, add user_id
to the SELECT
list. It's essential for your pagination.
'2023-03-25 00:11:56+01'
is the result of the date_bin()
expression. You might add it to the SELECT
list for simplicity. (I added it in the fiddle.)
Since your date_bin()
expression uses an arbitrary time anchor (and interval?), using an index is sophisticated, but still possible. Work with the lower / upper bounds of possible date_bin()
values ...