Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion named.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion named_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
}
})
}
Expand Down