LocustDB icon indicating copy to clipboard operation
LocustDB copied to clipboard

Support window functions like row_number()

Open jrmuizel opened this issue 4 years ago • 4 comments

This would be nice to have.

jrmuizel avatar Jul 04 '20 13:07 jrmuizel

There actually used to be support for an OFFSET clause and it looks like the query engine still supports that functionality, it was only unsupported by the new parser but looks like making this work again it fairly easy: https://github.com/cswinter/LocustDB/pull/136 Once that has landed, queries with an OFFSET <rows> ROWS clause should work.

cswinter avatar Jul 04 '20 15:07 cswinter

Fixed in v0.3.4

cswinter avatar Jul 04 '20 16:07 cswinter

I was looking to number the rows with a query like

SELECT x, y, row_number() OVER (ORDER BY y) AS row_number FROM t0 ORDER BY x;

jrmuizel avatar Jul 04 '20 17:07 jrmuizel

I see. Adding just the row_number() should be relatively straightforward, but the OVER (ORDER BY y) clause is more involved since it requires two separate sort/query passes which the query engine does not currently support. If there was support for arbitrary subqueries it might be possible to implement this as a desugaring compiler pass, though that's an even larger undertaking. I don't expect I will work on this in the foreseeable future.

cswinter avatar Jul 04 '20 17:07 cswinter