File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1818,11 +1818,16 @@ impl<'a> Parser<'a> {
18181818 } else if let Some(lambda) = self.try_parse_lambda()? {
18191819 return Ok(lambda);
18201820 } else {
1821- // Parentheses create a normal expression context.
1822- // This ensures that e.g. `NOT NULL` inside parens is parsed
1823- // as `IS NOT NULL` (for dialects that support it), while
1824- // `NOT NULL` outside parens in a column definition context
1825- // remains a column constraint.
1821+ // Parentheses in expressions switch to "normal" parsing state.
1822+ // This matters for dialects (SQLite, DuckDB) where `NOT NULL` can
1823+ // be an alias for `IS NOT NULL`. In column definitions like:
1824+ //
1825+ // CREATE TABLE t (c INT DEFAULT (42 NOT NULL) NOT NULL)
1826+ //
1827+ // The `(42 NOT NULL)` is an expression with parens, so it parses
1828+ // as `IsNotNull(42)`. The trailing `NOT NULL` is outside those
1829+ // expression parens (the outer parens are CREATE TABLE syntax),
1830+ // so it remains a column constraint.
18261831 let exprs = self.with_state(ParserState::Normal, |p| {
18271832 p.parse_comma_separated(Parser::parse_expr)
18281833 })?;
Original file line number Diff line number Diff line change @@ -17305,6 +17305,7 @@ fn test_parse_not_null_in_column_options() {
1730517305#[test]
1730617306fn test_parse_default_expr_with_operators() {
1730717307 all_dialects().verified_stmt("CREATE TABLE t (c INT DEFAULT (1 + 2) + 3)");
17308+ all_dialects().verified_stmt("CREATE TABLE t (c INT DEFAULT (1 + 2) + 3 NOT NULL)");
1730817309}
1730917310
1731017311#[test]
You can’t perform that action at this time.
0 commit comments