sqldelight icon indicating copy to clipboard operation
sqldelight copied to clipboard

Sqlite 3.25 dialect: OVER clause fails compilation

Open gabrielittner opened this issue 3 years ago • 8 comments

SQLDelight Version

master

Operating System

macOS

Gradle Version

7.2

Kotlin Version

1.5.31

AGP Version

No response

Describe the Bug

I wanted to try out Keyset Paging and added a query for it however compilation fails at the OVER clause despite changing the dialect to 3.25

Stacktrace

> Task :common:generateCommonMainHockeyDbInterface FAILED

/Users/gabriel/Downloads/sqldelight/sample/common/src/commonMain/sqldelight/com/example/sqldelight/hockey/data/Player.sq: (39, 31): ')' or <expr> expected, got 'ORDER'
34    SELECT id
35    FROM (
36      SELECT
37        id,
38        CASE
39          WHEN ((row_number() OVER(ORDER BY id ASC) - 0) % :limit) = 0 THEN 1
                                     ^^^^^
40          WHEN id = :anchor THEN 1
41          ELSE 0
42        END page_boundary

Gradle Build Script

Here is a reproducer where I added the sample from the docs and set the dialect to 3.25 in the sample project: https://github.com/cashapp/sqldelight/compare/master...gabrielittner:sample-over-clause

gabrielittner avatar Jan 28 '22 20:01 gabrielittner

Same issue here, any update?

b95505017 avatar Mar 21 '22 00:03 b95505017

@AlecStrong I took a stab at this by adding other_expr to overrides and adding

other_expr ::= {extension_expr} | window_function_invocation

to match the sqlite flow chart for expr but the error is still:

')' or <expr> expected, got 'ORDER'

eygraber avatar Apr 11 '22 20:04 eygraber

can you push a branch for me to look at?

AlecKazakova avatar Apr 11 '22 21:04 AlecKazakova

https://github.com/eygraber/sqldelight/tree/repro-2799

eygraber avatar Apr 12 '22 15:04 eygraber

you have to set it to override

other_expr ::= {extension_expr} | window_function_invocation {
  extends = ...
  implements = ...
  override = true
}

AlecKazakova avatar Apr 16 '22 15:04 AlecKazakova

Ah I had tested with that earlier but I forgot to include it in this branch. In any case, it still fails with the same error.

eygraber avatar Apr 18 '22 04:04 eygraber

:+1: thanks, will take a look

AlecKazakova avatar Apr 18 '22 12:04 AlecKazakova

Experiencing same issue here. Right now there doesn't seem to be a way to actually implement the query supplied in the docs unless I'm missing something.

mdpearce avatar Sep 17 '22 03:09 mdpearce

@AlecStrong I took another look (and updated https://github.com/eygraber/sqldelight/tree/repro-2799 to make the failing test actually be correct sqlite) and the only thing I can think of is that something else is getting matched before window_function_invocation; I just have no idea what it is

eygraber avatar Nov 17 '22 03:11 eygraber

Has anyone found a fix or workaround? I'm also running into this using the same dialect.

bryanstern avatar May 31 '23 18:05 bryanstern

To be clear, if it wasn't apparent, this is affecting me on the 3_38 dialect too

bqv avatar Jul 29 '23 23:07 bqv

@AlecKazakova any updates regarding this problem?

ted3x avatar Sep 30 '23 17:09 ted3x