Skip to content

Commit 585125e

Browse files
authored
compiler: Don't mutate table name (#517)
1 parent c36c9e1 commit 585125e

File tree

6 files changed

+99
-1
lines changed

6 files changed

+99
-1
lines changed

internal/compiler/output_columns.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ func outputColumns(qc *QueryCatalog, node ast.Node) ([]*Column, error) {
126126
cols = append(cols, &Column{
127127
Name: cname,
128128
Type: c.Type,
129+
Scope: scope,
129130
Table: c.Table,
130131
DataType: c.DataType,
131132
NotNull: c.NotNull,
@@ -262,7 +263,11 @@ func sourceTables(qc *QueryCatalog, node ast.Node) ([]*Table, error) {
262263
return nil, cerr
263264
}
264265
if n.Alias != nil {
265-
table.Rel.Name = *n.Alias.Aliasname
266+
table.Rel = &ast.TableName{
267+
Catalog: table.Rel.Catalog,
268+
Schema: table.Rel.Schema,
269+
Name: *n.Alias.Aliasname,
270+
}
266271
}
267272
tables = append(tables, table)
268273
default:

internal/endtoend/testdata/select_distinct/go/db.go

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

internal/endtoend/testdata/select_distinct/go/models.go

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

internal/endtoend/testdata/select_distinct/go/query.sql.go

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATE TABLE bar (id serial not null, name text);
2+
3+
-- name: GetBars :many
4+
SELECT DISTINCT ON (a.id) a.*
5+
FROM bar a;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"version": "1",
3+
"packages": [
4+
{
5+
"path": "go",
6+
"name": "querytest",
7+
"schema": "query.sql",
8+
"queries": "query.sql"
9+
}
10+
]
11+
}

0 commit comments

Comments
 (0)