Skip to content

Commit d6bb7a5

Browse files
committed
Pr feedback
1 parent 7f746c5 commit d6bb7a5

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

src/parser/mod.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff 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
})?;

tests/sqlparser_common.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17305,6 +17305,7 @@ fn test_parse_not_null_in_column_options() {
1730517305
#[test]
1730617306
fn 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]

0 commit comments

Comments
 (0)