diff --git a/named.go b/named.go index 6ac44777..af527aa0 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(`(?i)\WVALUES\s*\(`) func findMatchingClosingBracketIndex(s string) int { count := 0 diff --git a/named_test.go b/named_test.go index 0ee5b85f..c33b9bc5 100644 --- a/named_test.go +++ b/named_test.go @@ -422,6 +422,30 @@ func TestFixBounds(t *testing.T) { )`, loop: 2, }, + { + name: "use of VALUES not for insert", + query: ` +UPDATE t +SET + foo = u.foo, + bar = u.bar +FROM ( + VALUES (:id, :foo, :bar) +) AS u(id, foo, bar) +WHERE t.id = u.id +`, + expect: ` +UPDATE t +SET + foo = u.foo, + bar = u.bar +FROM ( + VALUES (:id, :foo, :bar),(:id, :foo, :bar) +) AS u(id, foo, bar) +WHERE t.id = u.id +`, + loop: 2, + }, } for _, tc := range table {