Skip to content

Commit

Permalink
fix(engine/sqlite): fixed IN operator precedence (#2428)
Browse files Browse the repository at this point in the history
* fix(engine/sqlite): fixed IN operator precedence

close #2368

* test: add endtoend

* chore: v1.19.1

* Regenerate parser

---------

Co-authored-by: Kyle Conroy <[email protected]>
  • Loading branch information
orisano and kyleconroy authored Jul 24, 2023
1 parent 6d3cdc2 commit 5ffe722
Show file tree
Hide file tree
Showing 8 changed files with 351 additions and 205 deletions.
31 changes: 31 additions & 0 deletions internal/endtoend/testdata/select_in_and/sqlite/go/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions internal/endtoend/testdata/select_in_and/sqlite/go/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions internal/endtoend/testdata/select_in_and/sqlite/go/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions internal/endtoend/testdata/select_in_and/sqlite/query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
-- Example queries for sqlc
CREATE TABLE authors (
id integer PRIMARY KEY,
name text NOT NULL,
age integer
);

CREATE TABLE translators (
id integer PRIMARY KEY,
name text NOT NULL,
age integer
);

CREATE TABLE books (
id integer PRIMARY KEY,
author text NOT NULL,
translator text NOT NULL,
year integer
);

-- name: DeleteAuthor :exec
DELETE FROM
books AS b
WHERE
b.author NOT IN (
SELECT
a.name
FROM
authors a
WHERE
a.age >= ?
)
AND b.translator NOT IN (
SELECT
t.name
FROM
translators t
WHERE
t.age >= ?
)
AND b.year <= ?;
1 change: 1 addition & 0 deletions internal/endtoend/testdata/select_in_and/sqlite/sqlc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version": "1", "packages": [{"path": "go", "engine": "sqlite", "schema": "query.sql", "queries": "query.sql", "name": "querytest"}]}
10 changes: 5 additions & 5 deletions internal/engine/sqlite/parser/SQLiteParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,11 @@ expr:
| MATCH_
| REGEXP_
) expr #expr_comparison
| expr NOT_? IN_ (
OPEN_PAR (select_stmt | expr ( COMMA expr)*)? CLOSE_PAR
| ( schema_name DOT)? table_name
| (schema_name DOT)? table_function_name OPEN_PAR (expr (COMMA expr)*)? CLOSE_PAR
) #expr_in_select
| expr AND_ expr #expr_binary
| expr OR_ expr #expr_binary
| qualified_function_name OPEN_PAR ((DISTINCT_? expr ( COMMA expr)*) | STAR)? CLOSE_PAR filter_clause? over_clause? #expr_function
Expand All @@ -310,11 +315,6 @@ expr:
)? #expr_comparison
| expr ( ISNULL_ | NOTNULL_ | NOT_ NULL_) #expr_null_comp
| expr NOT_? BETWEEN_ expr AND_ expr #expr_between
| expr NOT_? IN_ (
OPEN_PAR (select_stmt | expr ( COMMA expr)*)? CLOSE_PAR
| ( schema_name DOT)? table_name
| (schema_name DOT)? table_function_name OPEN_PAR (expr (COMMA expr)*)? CLOSE_PAR
) #expr_in_select
| ((NOT_)? EXISTS_)? OPEN_PAR select_stmt CLOSE_PAR #expr_in_select
| CASE_ expr? (WHEN_ expr THEN_ expr)+ (ELSE_ expr)? END_ #expr_case
| raise_function #expr_raise
Expand Down
2 changes: 1 addition & 1 deletion internal/engine/sqlite/parser/SQLiteParser.interp

Large diffs are not rendered by default.

Loading

0 comments on commit 5ffe722

Please sign in to comment.