diff --git a/named.go b/named.go index 728aa04d..5561eba5 100644 --- a/named.go +++ b/named.go @@ -224,7 +224,7 @@ func bindStruct(bindType int, query string, arg interface{}, m *reflectx.Mapper) return bound, arglist, nil } -var valuesReg = regexp.MustCompile(`\)\s*(?i)VALUES\s*\(`) +var valuesReg = regexp.MustCompile(`[)(]\s*(?i)VALUES\s*\(`) func findMatchingClosingBracketIndex(s string) int { count := 0 diff --git a/named_test.go b/named_test.go index 8481b35b..38751f0e 100644 --- a/named_test.go +++ b/named_test.go @@ -391,6 +391,18 @@ func TestFixBounds(t *testing.T) { expect: `INSERT INTO table_values (a, b) VALUES (:a, :b),(:a, :b)`, loop: 2, }, + { + name: `table named "values"`, + query: `INSERT INTO values (a, b) VALUES (:a, :b)`, + expect: `INSERT INTO values (a, b) VALUES (:a, :b),(:a, :b)`, + loop: 2, + }, + { + name: `select from values list`, + query: `SELECT * FROM (VALUES (:a, :b))`, + expect: `SELECT * FROM (VALUES (:a, :b),(:a, :b))`, + loop: 2, + }, { name: `multiline indented query`, query: `INSERT INTO foo ( @@ -428,7 +440,7 @@ func TestFixBounds(t *testing.T) { t.Run(tc.name, func(t *testing.T) { res := fixBound(tc.query, tc.loop) if res != tc.expect { - t.Errorf("mismatched results") + t.Errorf("mismatched results. Expected: %s, got: %s", tc.expect, res) } }) }