Skip to content

SQLite: Fix parsing of INSERT DEFAULT VALUES syntax #4010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2025
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
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