Skip to content
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

fix(compiler): Search SELECT and UPDATE the same way #2841

Merged
merged 2 commits into from
Oct 12, 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
7 changes: 4 additions & 3 deletions internal/compiler/output_columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,10 @@ func (c *Compiler) sourceTables(qc *QueryCatalog, node ast.Node) ([]*Table, erro
return ok
})
case *ast.UpdateStmt:
list = &ast.List{
Items: append(n.FromClause.Items, n.Relations.Items...),
}
var tv tableVisitor
astutils.Walk(&tv, n.FromClause)
astutils.Walk(&tv, n.Relations)
list = &tv.list
case *ast.DoStmt:
list = &ast.List{}
case *ast.CallStmt:
Expand Down
1 change: 1 addition & 0 deletions internal/endtoend/testdata/join_update/issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/sqlc-dev/sqlc/issues/1100
32 changes: 32 additions & 0 deletions internal/endtoend/testdata/join_update/postgresql/pgx/go/db.go

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

24 changes: 24 additions & 0 deletions internal/endtoend/testdata/join_update/postgresql/pgx/go/models.go

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- name: Percentile :exec
UPDATE group_calc_totals gct
SET npn = nem.npn
FROM producer_group_attribute ga
JOIN npn_external_map nem ON ga.npn_external_map_id = nem.id
WHERE gct.group_id = ga.group_id;
14 changes: 14 additions & 0 deletions internal/endtoend/testdata/join_update/postgresql/pgx/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CREATE TABLE group_calc_totals (
npn text,
group_id text
);

CREATE TABLE producer_group_attribute (
npn_external_map_id text,
group_id text
);

CREATE TABLE npn_external_map (
id text,
npn text
);
10 changes: 10 additions & 0 deletions internal/endtoend/testdata/join_update/postgresql/pgx/sqlc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "2"
sql:
- engine: "postgresql"
schema: "schema.sql"
queries: "query.sql"
gen:
go:
package: "querytest"
out: "go"
sql_package: "pgx/v5"
Loading