From 7fac5651f67822e363c18e9ced24858056aacb9b Mon Sep 17 00:00:00 2001 From: taylorchu Date: Tue, 15 Oct 2019 16:08:12 -0700 Subject: [PATCH] BUGFIX: don't auto add parentheses for union (#192) --- interpolate_test.go | 4 +++- union.go | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/interpolate_test.go b/interpolate_test.go index 7a71a0d6..bb45aedd 100644 --- a/interpolate_test.go +++ b/interpolate_test.go @@ -124,7 +124,9 @@ func TestInterpolateForDialect(t *testing.T) { Select("b").From("table2"), ).As("t"), }, - want: "((SELECT a FROM table1) UNION ALL (SELECT b FROM table2)) AS `t`", + // parentheses around union subqueries are not supported in sqlite + // but supported in both mysql and postgres. + want: "(SELECT a FROM table1 UNION ALL SELECT b FROM table2) AS `t`", }, { query: "?", diff --git a/union.go b/union.go index d0b2f8bb..453946b7 100644 --- a/union.go +++ b/union.go @@ -34,8 +34,10 @@ func (u *union) Build(d Dialect, buf Buffer) error { buf.WriteString("ALL ") } } - buf.WriteString(placeholder) - buf.WriteValue(b) + err := b.Build(d, buf) + if err != nil { + return err + } } return nil }