dialect/sql: append selector alias only if defined (#3399)

This commit is contained in:
Ariel Mashraki
2023-03-19 12:07:41 +02:00
committed by GitHub
parent 3f1063c77e
commit b340ed78cf
2 changed files with 9 additions and 2 deletions

View File

@@ -2824,8 +2824,10 @@ func (s *Selector) Query() (string, []any) {
b.Wrap(func(b *Builder) {
b.Join(t)
})
b.WriteString(" AS ")
b.Ident(t.as)
if t.as != "" {
b.WriteString(" AS ")
b.Ident(t.as)
}
case *WithBuilder:
t.SetDialect(s.dialect)
b.Ident(t.Name())

View File

@@ -1631,6 +1631,11 @@ WHERE (((("users"."id1" = "users"."id2" AND "users"."id1" <> "users"."id2")
AND "users"."id1" > "users"."id2") AND "users"."id1" >= "users"."id2")
AND "users"."id1" < "users"."id2") AND "users"."id1" <= "users"."id2"`, "\n", ""),
},
{
input: Select("name").
From(Select("name", "age").From(Table("users"))),
wantQuery: "SELECT `name` FROM (SELECT `name`, `age` FROM `users`)",
},
}
for i, tt := range tests {
t.Run(strconv.Itoa(i), func(t *testing.T) {