Skip to content
Merged
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
SQLite: Fix parsing of INSERT DEFAULT VALUES syntax
This commit fixes issue #3998 where SQLite's parser couldn't handle
the valid SQL syntax "INSERT INTO table DEFAULT VALUES".

The fix involves:
1. Updating the ANTLR grammar to properly support DEFAULT VALUES
   as part of the INSERT statement structure
2. Adding handling in convert.go for the DEFAULT VALUES case
3. Regenerating the parser from the updated grammar

Fixes #3998

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
  • Loading branch information
kyleconroy and claude committed Jul 1, 2025
commit f5dc474b30c0143207021369cddaa88a6e469cd5
31 changes: 31 additions & 0 deletions internal/endtoend/testdata/insert_default_values/sqlite/go/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- name: InsertWorkspace :exec
INSERT INTO workspace DEFAULT VALUES;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE TABLE workspace (
id INTEGER PRIMARY KEY AUTOINCREMENT
);
12 changes: 12 additions & 0 deletions internal/endtoend/testdata/insert_default_values/sqlite/sqlc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "1",
"packages": [
{
"engine": "sqlite",
"path": "go",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
}
]
}
20 changes: 19 additions & 1 deletion internal/engine/sqlite/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,25 @@ func (c *cc) convertInsert_stmtContext(n *parser.Insert_stmtContext) ast.Node {
ReturningList: c.convertReturning_caluseContext(n.Returning_clause()),
}

if n.Select_stmt() != nil {
// Check if this is a DEFAULT VALUES insert
hasDefaultValues := false
for _, child := range n.GetChildren() {
if term, ok := child.(antlr.TerminalNode); ok {
if term.GetSymbol().GetTokenType() == parser.SQLiteParserDEFAULT_ {
hasDefaultValues = true
break
}
}
}

if hasDefaultValues {
// For DEFAULT VALUES, create an empty select statement
insert.SelectStmt = &ast.SelectStmt{
FromClause: &ast.List{},
TargetList: &ast.List{},
ValuesLists: &ast.List{Items: []ast.Node{&ast.List{}}}, // Single empty values list
}
} else if n.Select_stmt() != nil {
if ss, ok := c.convert(n.Select_stmt()).(*ast.SelectStmt); ok {
ss.ValuesLists = &ast.List{}
insert.SelectStmt = ss
Expand Down
2 changes: 1 addition & 1 deletion internal/engine/sqlite/parser/SQLiteParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,9 @@ insert_stmt:
COMMA OPEN_PAR expr ( COMMA expr)* CLOSE_PAR
)*
| select_stmt
| DEFAULT_ VALUES_
) upsert_clause? returning_clause?
)
| DEFAULT_ VALUES_
;

upsert_clause:
Expand Down
2 changes: 1 addition & 1 deletion internal/engine/sqlite/parser/SQLiteParser.interp

Large diffs are not rendered by default.

3,882 changes: 1,930 additions & 1,952 deletions internal/engine/sqlite/parser/sqlite_parser.go

Large diffs are not rendered by default.

Loading