Skip to content

Commit fefa6f4

Browse files
authored
fix(compiler): support identifiers with schema (#2579)
* fix(compiler): support identifiers with schema close #1858 * test: update endtoend
1 parent f9e18c8 commit fefa6f4

File tree

9 files changed

+122
-1
lines changed

9 files changed

+122
-1
lines changed

internal/compiler/output_columns.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,19 +612,26 @@ func (c *Compiler) sourceTables(qc *QueryCatalog, node ast.Node) ([]*Table, erro
612612

613613
func outputColumnRefs(res *ast.ResTarget, tables []*Table, node *ast.ColumnRef) ([]*Column, error) {
614614
parts := stringSlice(node.Fields)
615-
var name, alias string
615+
var schema, name, alias string
616616
switch {
617617
case len(parts) == 1:
618618
name = parts[0]
619619
case len(parts) == 2:
620620
alias = parts[0]
621621
name = parts[1]
622+
case len(parts) == 3:
623+
schema = parts[0]
624+
alias = parts[1]
625+
name = parts[2]
622626
default:
623627
return nil, fmt.Errorf("unknown number of fields: %d", len(parts))
624628
}
625629
var cols []*Column
626630
var found int
627631
for _, t := range tables {
632+
if schema != "" && t.Rel.Schema != schema {
633+
continue
634+
}
628635
if alias != "" && t.Rel.Name != alias {
629636
continue
630637
}

internal/endtoend/testdata/schema_scoped_list/mysql/go/query.sql.go

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

internal/endtoend/testdata/schema_scoped_list/mysql/query.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ CREATE TABLE foo.bar (id serial not null);
33

44
-- name: SchemaScopedList :many
55
SELECT * FROM foo.bar;
6+
7+
-- name: SchemaScopedColList :many
8+
SELECT foo.bar.id FROM foo.bar;

internal/endtoend/testdata/schema_scoped_list/postgresql/pgx/v4/go/query.sql.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/schema_scoped_list/postgresql/pgx/v4/query.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ CREATE TABLE foo.bar (id serial not null);
33

44
-- name: SchemaScopedList :many
55
SELECT * FROM foo.bar;
6+
7+
-- name: SchemaScopedColList :many
8+
SELECT foo.bar.id FROM foo.bar;

internal/endtoend/testdata/schema_scoped_list/postgresql/pgx/v5/go/query.sql.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/schema_scoped_list/postgresql/pgx/v5/query.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ CREATE TABLE foo.bar (id serial not null);
33

44
-- name: SchemaScopedList :many
55
SELECT * FROM foo.bar;
6+
7+
-- name: SchemaScopedColList :many
8+
SELECT foo.bar.id FROM foo.bar;

internal/endtoend/testdata/schema_scoped_list/postgresql/stdlib/go/query.sql.go

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

internal/endtoend/testdata/schema_scoped_list/postgresql/stdlib/query.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ CREATE TABLE foo.bar (id serial not null);
33

44
-- name: SchemaScopedList :many
55
SELECT * FROM foo.bar;
6+
7+
-- name: SchemaScopedColList :many
8+
SELECT foo.bar.id FROM foo.bar;

0 commit comments

Comments
 (0)