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))) + } } } 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}