From 5c82b72e5fde11580ff9d329f21a94c54bdf8a6b Mon Sep 17 00:00:00 2001 From: Jussi Saurio Date: Wed, 24 Sep 2025 09:54:43 +0300 Subject: [PATCH] fix INSERT INTO t DEFAULT VALUES --- core/translate/insert.rs | 22 ++++++++++++++++++---- testing/insert.test | 8 ++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/core/translate/insert.rs b/core/translate/insert.rs index f760a8106..e82f39e46 100644 --- a/core/translate/insert.rs +++ b/core/translate/insert.rs @@ -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(); diff --git a/testing/insert.test b/testing/insert.test index dbd20af3f..059e42f54 100755 --- a/testing/insert.test +++ b/testing/insert.test @@ -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|} \ No newline at end of file