circuithub / rel8

Hey! Hey! Can u rel8?
https://rel8.readthedocs.io
Other
150 stars 38 forks source link

Anonymous ROW expressions? #216

Open AnthonySuper opened 1 year ago

AnthonySuper commented 1 year ago

Postgres allows you to create anonymous rows for use in queries. This is quite helpful when doing keyset pagination. The following SQL...

SELECT * FROM users
WHERE (userRank, id) > (10, 100)

is much nicer than...

SELECT * FROM users
WHERE userRank > 10
OR (userRank = 10 AND id > 100)

The already-existing Composite type comes close, but it requires that the composite be named, instead of just an anonymous row. Would there be interest in support for this functionality in this library? I could try to make a patch if so.

ocharles commented 1 year ago

I'm not sure I've been convinced yet. Yes, that SQL might be convenient, but in Rel8 you can already do

where_ $ (userRank, id) >: lit (10, 100)

Does that solve your problem?