diff --git a/schemas/quote.go b/schemas/quote.go index c44abe25..a0070048 100644 --- a/schemas/quote.go +++ b/schemas/quote.go @@ -82,9 +82,7 @@ func (q Quoter) JoinWrite(b *strings.Builder, a []string, sep string) error { return err } } - if s != "*" { - q.QuoteTo(b, strings.TrimSpace(s)) - } + q.QuoteTo(b, strings.TrimSpace(s)) } return nil } @@ -143,7 +141,7 @@ func (q Quoter) quoteWordTo(buf *strings.Builder, word string) error { } isReserved := q.IsReserved(realWord) - if isReserved { + if isReserved && realWord != "*" { if err := buf.WriteByte(q.Prefix); err != nil { return err } @@ -151,7 +149,7 @@ func (q Quoter) quoteWordTo(buf *strings.Builder, word string) error { if _, err := buf.WriteString(realWord); err != nil { return err } - if isReserved { + if isReserved && realWord != "*" { return buf.WriteByte(q.Suffix) } diff --git a/schemas/quote_test.go b/schemas/quote_test.go index 708b450e..8e351dc0 100644 --- a/schemas/quote_test.go +++ b/schemas/quote_test.go @@ -22,6 +22,7 @@ func TestAlwaysQuoteTo(t *testing.T) { {"[mytable]", "`mytable`"}, {"[mytable]", `[mytable]`}, {`["mytable"]`, `"mytable"`}, + {`[mytable].*`, `[mytable].*`}, {"[myschema].[mytable]", "myschema.mytable"}, {"[myschema].[mytable]", "`myschema`.mytable"}, {"[myschema].[mytable]", "myschema.`mytable`"}, @@ -65,6 +66,7 @@ func TestReversedQuoteTo(t *testing.T) { {"[mytable]", "mytable"}, {"[mytable]", "`mytable`"}, {"[mytable]", `[mytable]`}, + {"[mytable].*", `[mytable].*`}, {`"mytable"`, `"mytable"`}, {"myschema.[mytable]", "myschema.mytable"}, {"myschema.[mytable]", "`myschema`.mytable"}, @@ -98,6 +100,7 @@ func TestNoQuoteTo(t *testing.T) { {"mytable", "mytable"}, {"mytable", "`mytable`"}, {"mytable", `[mytable]`}, + {"mytable.*", `[mytable].*`}, {`"mytable"`, `"mytable"`}, {"myschema.mytable", "myschema.mytable"}, {"myschema.mytable", "`myschema`.mytable"}, @@ -127,6 +130,8 @@ func TestJoin(t *testing.T) { assert.EqualValues(t, "[a],[b]", quoter.Join([]string{"a", " b"}, ",")) + assert.EqualValues(t, "[a].*,[b].[c]", quoter.Join([]string{"a.*", " b.c"}, ",")) + assert.EqualValues(t, "[f1], [f2], [f3]", quoter.Join(cols, ", ")) quoter.IsReserved = AlwaysNoReserve @@ -134,11 +139,11 @@ func TestJoin(t *testing.T) { } func TestStrings(t *testing.T) { - cols := []string{"f1", "f2", "t3.f3"} + cols := []string{"f1", "f2", "t3.f3", "t4.*"} quoter := Quoter{'[', ']', AlwaysReserve} quotedCols := quoter.Strings(cols) - assert.EqualValues(t, []string{"[f1]", "[f2]", "[t3].[f3]"}, quotedCols) + assert.EqualValues(t, []string{"[f1]", "[f2]", "[t3].[f3]", "[t4].*"}, quotedCols) } func TestTrim(t *testing.T) {