Skip to content

fix(compiler): Check delete statements for CTEs #1329

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 1 commit into from
Dec 9, 2021
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
2 changes: 2 additions & 0 deletions internal/compiler/query_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ type QueryCatalog struct {
func buildQueryCatalog(c *catalog.Catalog, node ast.Node) (*QueryCatalog, error) {
var with *ast.WithClause
switch n := node.(type) {
case *ast.DeleteStmt:
with = n.WithClause
case *ast.InsertStmt:
with = n.WithClause
case *ast.UpdateStmt:
Expand Down
29 changes: 29 additions & 0 deletions internal/endtoend/testdata/cte_in_delete/mysql/go/db.go

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

10 changes: 10 additions & 0 deletions internal/endtoend/testdata/cte_in_delete/mysql/go/models.go

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

20 changes: 20 additions & 0 deletions internal/endtoend/testdata/cte_in_delete/mysql/go/query.sql.go

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

7 changes: 7 additions & 0 deletions internal/endtoend/testdata/cte_in_delete/mysql/query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE bar (id integer NOT NULL AUTO_INCREMENT PRIMARY KEY, ready bool not null);

-- name: DeleteReadyWithCTE :exec
WITH ready_ids AS (
SELECT id FROM bar WHERE ready
)
DELETE FROM bar WHERE id IN (SELECT * FROM ready_ids);
12 changes: 12 additions & 0 deletions internal/endtoend/testdata/cte_in_delete/mysql/sqlc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "1",
"packages": [
{
"engine": "mysql",
"path": "go",
"name": "querytest",
"schema": "query.sql",
"queries": "query.sql"
}
]
}
30 changes: 30 additions & 0 deletions internal/endtoend/testdata/cte_in_delete/pgx/go/db.go

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

10 changes: 10 additions & 0 deletions internal/endtoend/testdata/cte_in_delete/pgx/go/models.go

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

36 changes: 36 additions & 0 deletions internal/endtoend/testdata/cte_in_delete/pgx/go/query.sql.go

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

8 changes: 8 additions & 0 deletions internal/endtoend/testdata/cte_in_delete/pgx/query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE TABLE bar (id serial primary key not null, ready bool not null);

-- name: DeleteReadyWithCTE :many
WITH ready_ids AS (
SELECT id FROM bar WHERE ready
)
DELETE FROM bar WHERE id IN (SELECT * FROM ready_ids)
RETURNING id;
13 changes: 13 additions & 0 deletions internal/endtoend/testdata/cte_in_delete/pgx/sqlc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "1",
"packages": [
{
"path": "go",
"engine": "postgresql",
"sql_package": "pgx/v4",
"name": "querytest",
"schema": "query.sql",
"queries": "query.sql"
}
]
}
29 changes: 29 additions & 0 deletions internal/endtoend/testdata/cte_in_delete/stdlib/go/db.go

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

10 changes: 10 additions & 0 deletions internal/endtoend/testdata/cte_in_delete/stdlib/go/models.go

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

39 changes: 39 additions & 0 deletions internal/endtoend/testdata/cte_in_delete/stdlib/go/query.sql.go

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

8 changes: 8 additions & 0 deletions internal/endtoend/testdata/cte_in_delete/stdlib/query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE TABLE bar (id serial primary key not null, ready bool not null);

-- name: DeleteReadyWithCTE :many
WITH ready_ids AS (
SELECT id FROM bar WHERE ready
)
DELETE FROM bar WHERE id IN (SELECT * FROM ready_ids)
RETURNING id;
11 changes: 11 additions & 0 deletions internal/endtoend/testdata/cte_in_delete/stdlib/sqlc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "1",
"packages": [
{
"path": "go",
"name": "querytest",
"schema": "query.sql",
"queries": "query.sql"
}
]
}