Skip to content
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
28 changes: 20 additions & 8 deletions internal/compiler/output_columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,23 @@ func isTableRequired(n ast.Node, col *Column, prior int) int {
return tableNotFound
}

type tableVisitor struct {
list ast.List
}

func (r *tableVisitor) Visit(n ast.Node) astutils.Visitor {
switch n.(type) {
case *ast.RangeVar, *ast.RangeFunction:
r.list.Items = append(r.list.Items, n)
return r
case *ast.RangeSubselect:
r.list.Items = append(r.list.Items, n)
return nil
default:
return r
}
}

// Compute the output columns for a statement.
//
// Return an error if column references are ambiguous
Expand All @@ -470,14 +487,9 @@ func (c *Compiler) sourceTables(qc *QueryCatalog, node ast.Node) ([]*Table, erro
Items: []ast.Node{n.Relation},
}
case *ast.SelectStmt:
list = astutils.Search(n.FromClause, func(node ast.Node) bool {
switch node.(type) {
case *ast.RangeVar, *ast.RangeSubselect, *ast.RangeFunction:
return true
default:
return false
}
})
var tv tableVisitor
astutils.Walk(&tv, n.FromClause)
list = &tv.list
case *ast.TruncateStmt:
list = astutils.Search(n.Relations, func(node ast.Node) bool {
_, ok := node.(*ast.RangeVar)
Expand Down
27 changes: 27 additions & 0 deletions internal/endtoend/testdata/select_star/mysql/go/query.sql.go

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

3 changes: 3 additions & 0 deletions internal/endtoend/testdata/select_star/mysql/query.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/* name: GetAll :many */
SELECT * FROM users;

/* name: GetIDAll :many */
SELECT * FROM (SELECT id FROM users) t;

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
@@ -1,2 +1,5 @@
-- name: GetAll :many
SELECT * FROM users;

/* name: GetIDAll :many */
SELECT * FROM (SELECT id FROM users) t;

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
@@ -1,2 +1,5 @@
-- name: GetAll :many
SELECT * FROM users;

/* name: GetIDAll :many */
SELECT * FROM (SELECT id FROM users) t;

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
@@ -1,2 +1,5 @@
-- name: GetAll :many
SELECT * FROM users;

/* name: GetIDAll :many */
SELECT * FROM (SELECT id FROM users) t;
27 changes: 27 additions & 0 deletions internal/endtoend/testdata/select_star/sqlite/go/query.sql.go

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

3 changes: 3 additions & 0 deletions internal/endtoend/testdata/select_star/sqlite/query.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
-- name: GetAll :many
SELECT * FROM users;

/* name: GetIDAll :many */
SELECT * FROM (SELECT id FROM users) t;