Skip to content

Commit 27e47b9

Browse files
authored
fix(compiler): Search SELECT and UPDATE the same way (#2841)
* fix(compiler): Search SELECT and UPDATE the same way * Update sqlc.yaml
1 parent f09d96f commit 27e47b9

File tree

8 files changed

+114
-3
lines changed

8 files changed

+114
-3
lines changed

internal/compiler/output_columns.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,10 @@ func (c *Compiler) sourceTables(qc *QueryCatalog, node ast.Node) ([]*Table, erro
507507
return ok
508508
})
509509
case *ast.UpdateStmt:
510-
list = &ast.List{
511-
Items: append(n.FromClause.Items, n.Relations.Items...),
512-
}
510+
var tv tableVisitor
511+
astutils.Walk(&tv, n.FromClause)
512+
astutils.Walk(&tv, n.Relations)
513+
list = &tv.list
513514
case *ast.DoStmt:
514515
list = &ast.List{}
515516
case *ast.CallStmt:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/sqlc-dev/sqlc/issues/1100

internal/endtoend/testdata/join_update/postgresql/pgx/go/db.go

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/join_update/postgresql/pgx/go/models.go

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/join_update/postgresql/pgx/go/query.sql.go

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- name: Percentile :exec
2+
UPDATE group_calc_totals gct
3+
SET npn = nem.npn
4+
FROM producer_group_attribute ga
5+
JOIN npn_external_map nem ON ga.npn_external_map_id = nem.id
6+
WHERE gct.group_id = ga.group_id;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CREATE TABLE group_calc_totals (
2+
npn text,
3+
group_id text
4+
);
5+
6+
CREATE TABLE producer_group_attribute (
7+
npn_external_map_id text,
8+
group_id text
9+
);
10+
11+
CREATE TABLE npn_external_map (
12+
id text,
13+
npn text
14+
);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: "2"
2+
sql:
3+
- engine: "postgresql"
4+
schema: "schema.sql"
5+
queries: "query.sql"
6+
gen:
7+
go:
8+
package: "querytest"
9+
out: "go"
10+
sql_package: "pgx/v5"

0 commit comments

Comments
 (0)