Skip to content

Commit

Permalink
fix(compiler): Search SELECT and UPDATE the same way (#2841)
Browse files Browse the repository at this point in the history
* fix(compiler): Search SELECT and UPDATE the same way

* Update sqlc.yaml
  • Loading branch information
kyleconroy authored Oct 12, 2023
1 parent f09d96f commit 27e47b9
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 3 deletions.
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"

0 comments on commit 27e47b9

Please sign in to comment.