Skip to content

Commit 3290843

Browse files
kyleconroyclaude
andcommitted
fix(ast): fix VALUES clause formatting to output multiple rows
The VALUES clause was incorrectly formatting multiple rows as a single row with multiple columns. For example: VALUES ('A'), ('B'), ('C') was being formatted as: VALUES ('A', 'B', 'C') This caused the star expander to think the VALUES table had 3 columns instead of 1, resulting in incorrect SELECT * expansion. The fix properly iterates over each row in ValuesLists and wraps each in parentheses. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 7d5caa7 commit 3290843

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

internal/endtoend/testdata/accurate_cte_values/postgresql/stdlib/go/query.sql.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/sql/ast/select_stmt.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,16 @@ func (n *SelectStmt) Format(buf *TrackedBuffer, d format.Dialect) {
3737
}
3838

3939
if items(n.ValuesLists) {
40-
buf.WriteString("VALUES (")
41-
buf.astFormat(n.ValuesLists, d)
42-
buf.WriteString(")")
40+
buf.WriteString("VALUES ")
41+
// ValuesLists is a list of rows, where each row is a List of values
42+
for i, row := range n.ValuesLists.Items {
43+
if i > 0 {
44+
buf.WriteString(", ")
45+
}
46+
buf.WriteString("(")
47+
buf.astFormat(row, d)
48+
buf.WriteString(")")
49+
}
4350
return
4451
}
4552

0 commit comments

Comments
 (0)