Skip to content

Commit b638d7d

Browse files
committed
Relax constraint on VALUE clause expansion
This lets it be used in non-INSERT scenarios as well. See the test for such an example.
1 parent 41dac16 commit b638d7d

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

named.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func bindStruct(bindType int, query string, arg interface{}, m *reflectx.Mapper)
224224
return bound, arglist, nil
225225
}
226226

227-
var valuesReg = regexp.MustCompile(`\)\s*(?i)VALUES\s*\(`)
227+
var valuesReg = regexp.MustCompile(`(?i)\WVALUES\s*\(`)
228228

229229
func findMatchingClosingBracketIndex(s string) int {
230230
count := 0

named_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,30 @@ func TestFixBounds(t *testing.T) {
422422
)`,
423423
loop: 2,
424424
},
425+
{
426+
name: "use of VALUES not for insert",
427+
query: `
428+
UPDATE t
429+
SET
430+
foo = u.foo,
431+
bar = u.bar
432+
FROM (
433+
VALUES (:id, :foo, :bar)
434+
) AS u(id, foo, bar)
435+
WHERE t.id = u.id
436+
`,
437+
expect: `
438+
UPDATE t
439+
SET
440+
foo = u.foo,
441+
bar = u.bar
442+
FROM (
443+
VALUES (:id, :foo, :bar),(:id, :foo, :bar)
444+
) AS u(id, foo, bar)
445+
WHERE t.id = u.id
446+
`,
447+
loop: 2,
448+
},
425449
}
426450

427451
for _, tc := range table {

0 commit comments

Comments
 (0)