Skip to content

fix(compiler): support identifiers with schema #2579

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

Merged
merged 2 commits into from
Aug 28, 2023
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
9 changes: 8 additions & 1 deletion internal/compiler/output_columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,19 +595,26 @@ func (c *Compiler) sourceTables(qc *QueryCatalog, node ast.Node) ([]*Table, erro

func outputColumnRefs(res *ast.ResTarget, tables []*Table, node *ast.ColumnRef) ([]*Column, error) {
parts := stringSlice(node.Fields)
var name, alias string
var schema, name, alias string
switch {
case len(parts) == 1:
name = parts[0]
case len(parts) == 2:
alias = parts[0]
name = parts[1]
case len(parts) == 3:
schema = parts[0]
alias = parts[1]
name = parts[2]
default:
return nil, fmt.Errorf("unknown number of fields: %d", len(parts))
}
var cols []*Column
var found int
for _, t := range tables {
if schema != "" && t.Rel.Schema != schema {
continue
}
if alias != "" && t.Rel.Name != alias {
continue
}
Expand Down

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/schema_scoped_list/mysql/query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ CREATE TABLE foo.bar (id serial not null);

-- name: SchemaScopedList :many
SELECT * FROM foo.bar;

-- name: SchemaScopedColList :many
SELECT foo.bar.id FROM foo.bar;

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
Expand Up @@ -3,3 +3,6 @@ CREATE TABLE foo.bar (id serial not null);

-- name: SchemaScopedList :many
SELECT * FROM foo.bar;

-- name: SchemaScopedColList :many
SELECT foo.bar.id FROM foo.bar;

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
Expand Up @@ -3,3 +3,6 @@ CREATE TABLE foo.bar (id serial not null);

-- name: SchemaScopedList :many
SELECT * FROM foo.bar;

-- name: SchemaScopedColList :many
SELECT foo.bar.id FROM foo.bar;

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
Expand Up @@ -3,3 +3,6 @@ CREATE TABLE foo.bar (id serial not null);

-- name: SchemaScopedList :many
SELECT * FROM foo.bar;

-- name: SchemaScopedColList :many
SELECT foo.bar.id FROM foo.bar;