rel8 icon indicating copy to clipboard operation
rel8 copied to clipboard

Dynamic limit and offset

Open shane-circuithub opened this issue 11 months ago • 3 comments

shane-circuithub avatar Jan 29 '25 19:01 shane-circuithub

Is PG this universally happy with this? It probably is, but for some reason I feel this comes with caveats!

ocharles avatar Jan 31 '25 11:01 ocharles

Is PG this universally happy with this? It probably is, but for some reason I feel this comes with caveats!

If there's any kind of tradeoff involved, could we keep the old limit and call this one something else?

At my workplace we have this code in our utilities and I'm excited to replace it with this PR!

-- | A workaround for the fact that Rel8 doesn't expose a version of LIMIT with
-- an `Expr` for the count.
dynamicLimit :: (DBIntegral n) => Expr n -> Query a -> Query a
dynamicLimit n q = do
  (i, v) <- indexed q
  where_ $ i <. Rel8.fromIntegral n
  pure v

sfwc avatar Jan 31 '25 12:01 sfwc

Yeah, it would be good to give the dynamic version a new name and avoid a breaking change to the old versions IMO

TeofilC avatar Jan 31 '25 12:01 TeofilC