Skip to content

fix(engine/sqlite): fixed IN operator precedence #2428

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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