Skip to content

Commit

Permalink
Fix schema/table escaping with alias in join (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
lafriks committed Aug 17, 2023
1 parent 547c9b6 commit 1d87de1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions builder/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ func (b Buffer) escape(table, value string) string {

var escaped_table string
if table != "" {
if i := strings.Index(strings.ToLower(table), " as "); i > -1 {
return b.escape(table[:i], "") + " AS " + b.Quoter.ID(table[i+4:])
}
if b.AllowTableSchema && strings.IndexByte(table, '.') >= 0 {
parts := strings.Split(table, ".")
for i, part := range parts {
Expand Down
4 changes: 4 additions & 0 deletions builder/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ func TestBuffer_escape(t *testing.T) {
field: "person.address as person.address",
result: "[person].[address] AS [person.address]",
},
{
table: "schema.user as primary_user",
result: "[schema].[user] AS [primary_user]",
},
}
for _, test := range tests {
t.Run(test.result, func(t *testing.T) {
Expand Down

0 comments on commit 1d87de1

Please sign in to comment.