Skip to content

fix: count column aliases only once #2399

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

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 5 additions & 1 deletion internal/compiler/output_columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ func findColumnForRef(ref *ast.ColumnRef, tables []*Table, selectStatement *ast.
}

var found int
var foundResTarget *ast.ResTarget
for _, t := range tables {
if alias != "" && t.Rel.Name != alias {
continue
Expand All @@ -686,7 +687,10 @@ func findColumnForRef(ref *ast.ColumnRef, tables []*Table, selectStatement *ast.
continue
}
if resTarget.Name != nil && *resTarget.Name == name {
found++
if resTarget != foundResTarget {
found++
foundResTarget = resTarget
}
}
}
}
Expand Down
31 changes: 31 additions & 0 deletions internal/endtoend/testdata/join_group_order/postgresql/go/db.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.

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

17 changes: 17 additions & 0 deletions internal/endtoend/testdata/join_group_order/postgresql/query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- Example queries for sqlc
CREATE TABLE authors (
id INT
);

CREATE TABLE books (
id INT,
author_id INT,
price INT
);

-- name: ListAuthorsByCheapestBook :many
SELECT
author_id, min(b.price) as min_price
From books b inner join authors a on a.id = b.author_id
GROUP BY b.author_id
ORDER BY min_price;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 1
packages:
- path: "go"
name: "querytest"
engine: "postgresql"
schema: "query.sql"
queries: "query.sql"