Merge 'Fix INSERT INTO t DEFAULT VALUES' from Jussi Saurio

Closes #3279

Closes #3291
This commit is contained in:
Pekka Enberg
2025-09-24 11:09:27 +03:00
committed by GitHub
2 changed files with 26 additions and 4 deletions

View File

@@ -348,10 +348,24 @@ pub fn translate_insert(
(result.num_result_cols, cursor_id)
}
}
InsertBody::DefaultValues => (
0,
program.alloc_cursor_id(CursorType::BTreeTable(btree_table.clone())),
),
InsertBody::DefaultValues => {
let num_values = table.columns().len();
values = Some(
table
.columns()
.iter()
.map(|c| {
c.default
.clone()
.unwrap_or(Box::new(ast::Expr::Literal(ast::Literal::Null)))
})
.collect(),
);
(
num_values,
program.alloc_cursor_id(CursorType::BTreeTable(btree_table.clone())),
)
}
};
let has_upsert = upsert_opt.is_some();

View File

@@ -633,3 +633,11 @@ do_execsql_test_on_specific_db {:memory:} boolean-literal-edgecase-false {
CREATE TABLE false (id INTEGER, true TEXT);
INSERT INTO false (id, true) VALUES (1, false) RETURNING id, false;
} {1|0}
do_execsql_test_on_specific_db {:memory:} default-values-population {
CREATE TABLE t (x INTEGER PRIMARY KEY, y DEFAULT 666, z);
INSERT INTO t DEFAULT VALUES;
INSERT INTO t DEFAULT VALUES;
SELECT * FROM t;
} {1|666|
2|666|}