From 892fcc881df1afe91b04f9bd18472047af1447c6 Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Tue, 21 Oct 2025 21:15:35 -0400 Subject: [PATCH 1/2] Handle TRUE|FALSE literal case for default column constraint in the parser --- parser/src/parser.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/parser/src/parser.rs b/parser/src/parser.rs index bbab464ff..1563f3e8b 100644 --- a/parser/src/parser.rs +++ b/parser/src/parser.rs @@ -3120,9 +3120,17 @@ impl<'a> Parser<'a> { TK_NULL | TK_BLOB | TK_STRING | TK_FLOAT | TK_INTEGER | TK_CTIME_KW => { Ok(ColumnConstraint::Default(self.parse_term()?)) } - _ => Ok(ColumnConstraint::Default(Box::new(Expr::Id( - self.parse_nm()?, - )))), + _ => { + let name = self.parse_nm()?; + let expr = if name.as_str().eq_ignore_ascii_case("true") { + Expr::Literal(Literal::Numeric("1".into())) + } else if name.as_str().eq_ignore_ascii_case("false") { + Expr::Literal(Literal::Numeric("0".into())) + } else { + Expr::Id(name) + }; + Ok(ColumnConstraint::Default(Box::new(expr))) + } } } From 2f401c0bcc5f89820276b52ef7cb743008d0846a Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Tue, 21 Oct 2025 21:22:09 -0400 Subject: [PATCH 2/2] Add regression tcl test for #3796 default bool col constraints --- testing/create_table.test | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/testing/create_table.test b/testing/create_table.test index e17196c9f..e0182828c 100755 --- a/testing/create_table.test +++ b/testing/create_table.test @@ -101,3 +101,17 @@ do_execsql_test_in_memory_any_error create_view_index_collision-1 { CREATE INDEX ix_same ON t4(w); CREATE VIEW ix_same AS SELECT 1; } + +# https://github.com/tursodatabase/turso/issues/3796 +do_execsql_test_on_specific_db {:memory:} col-default-true { + create table t(id integer primary key, a default true); + insert into t (id) values (1); + SELECT a from t; +} {1} + +# https://github.com/tursodatabase/turso/issues/3796 +do_execsql_test_on_specific_db {:memory:} col-default-false { + create table t(id integer primary key, a default false); + insert into t (id) values (1); + SELECT a from t; +} {0}