Skip to content

Commit 8b376b8

Browse files
committed
fixup: address next round of feedback
1 parent 0c56a51 commit 8b376b8

2 files changed

Lines changed: 20 additions & 29 deletions

File tree

src/parser/mod.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7787,7 +7787,7 @@ impl<'a> Parser<'a> {
77877787
} else if dialect_of!(self is ClickHouseDialect| GenericDialect)
77887788
&& self.parse_keyword(Keyword::ALIAS)
77897789
{
7790-
Ok(Some(ColumnOption::Alias(self.parse_expr()?)))
7790+
Ok(Some(ColumnOption::Alias(self.parse_column_option_expr()?)))
77917791
} else if dialect_of!(self is ClickHouseDialect| GenericDialect)
77927792
&& self.parse_keyword(Keyword::EPHEMERAL)
77937793
{
@@ -7796,7 +7796,9 @@ impl<'a> Parser<'a> {
77967796
if matches!(self.peek_token().token, Token::Comma | Token::RParen) {
77977797
Ok(Some(ColumnOption::Ephemeral(None)))
77987798
} else {
7799-
Ok(Some(ColumnOption::Ephemeral(Some(self.parse_expr()?))))
7799+
Ok(Some(ColumnOption::Ephemeral(Some(
7800+
self.parse_column_option_expr()?,
7801+
))))
78007802
}
78017803
} else if self.parse_keywords(&[Keyword::PRIMARY, Keyword::KEY]) {
78027804
let characteristics = self.parse_constraint_characteristics()?;
@@ -7874,7 +7876,7 @@ impl<'a> Parser<'a> {
78747876
} else if self.parse_keywords(&[Keyword::ON, Keyword::UPDATE])
78757877
&& dialect_of!(self is MySqlDialect | GenericDialect)
78767878
{
7877-
let expr = self.parse_expr()?;
7879+
let expr = self.parse_column_option_expr()?;
78787880
Ok(Some(ColumnOption::OnUpdate(expr)))
78797881
} else if self.parse_keyword(Keyword::GENERATED) {
78807882
self.parse_optional_column_option_generated()
@@ -7892,7 +7894,9 @@ impl<'a> Parser<'a> {
78927894
} else if self.parse_keyword(Keyword::SRID)
78937895
&& dialect_of!(self is MySqlDialect | GenericDialect)
78947896
{
7895-
Ok(Some(ColumnOption::Srid(Box::new(self.parse_expr()?))))
7897+
Ok(Some(ColumnOption::Srid(Box::new(
7898+
self.parse_column_option_expr()?,
7899+
))))
78967900
} else if self.parse_keyword(Keyword::IDENTITY)
78977901
&& dialect_of!(self is MsSqlDialect | GenericDialect)
78987902
{
@@ -7934,7 +7938,7 @@ impl<'a> Parser<'a> {
79347938

79357939
/// When parsing some column option expressions we need to revert to [ParserState::Normal] since
79367940
/// `NOT NULL` is allowed as an alias for `IS NOT NULL`.
7937-
/// In those cases we use this helper instead of calling [parse_expr] directly.
7941+
/// In those cases we use this helper instead of calling [Parser::parse_expr] directly.
79387942
///
79397943
/// For example, consider these `CREATE TABLE` statements:
79407944
/// ```sql

tests/sqlparser_common.rs

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16032,13 +16032,10 @@ fn parse_create_procedure_with_parameter_modes() {
1603216032
}
1603316033

1603416034
#[test]
16035-
fn parse_not_null_supported() {
16035+
fn parse_not_null() {
1603616036
let _ = all_dialects().expr_parses_to("x NOT NULL", "x IS NOT NULL");
1603716037
let _ = all_dialects().expr_parses_to("NULL NOT NULL", "NULL IS NOT NULL");
16038-
}
1603916038

16040-
#[test]
16041-
fn test_not_null_precedence() {
1604216039
assert_matches!(
1604316040
all_dialects().expr_parses_to("NOT NULL NOT NULL", "NOT NULL IS NOT NULL"),
1604416041
Expr::UnaryOp {
@@ -16200,37 +16197,27 @@ fn test_identifier_unicode_start() {
1620016197
}
1620116198

1620216199
#[test]
16203-
fn parse_notnull_unsupported() {
16204-
// Only Postgres, DuckDB, and SQLite support `x NOTNULL` as an expression
16205-
// All other dialects consider `x NOTNULL` like `x AS NOTNULL` and thus
16206-
// consider `NOTNULL` an alias for x.
16207-
let dialects = all_dialects_except(|d| d.supports_notnull_operator());
16208-
let _ = dialects
16200+
fn parse_notnull() {
16201+
// Some dialects support `x NOTNULL` as an expression while others consider
16202+
// `x NOTNULL` like `x AS NOTNULL` and thus consider `NOTNULL` an alias for x.
16203+
let notnull_unsupported_dialects = all_dialects_except(|d| d.supports_notnull_operator());
16204+
let _ = notnull_unsupported_dialects
1620916205
.verified_only_select_with_canonical("SELECT NULL NOTNULL", "SELECT NULL AS NOTNULL");
16210-
}
1621116206

16212-
#[test]
16213-
fn parse_notnull_supported() {
16214-
// Postgres, DuckDB and SQLite support `x NOTNULL` as an alias for `x IS NOT NULL`
16215-
let dialects = all_dialects_where(|d| d.supports_notnull_operator());
16216-
let _ = dialects.expr_parses_to("x NOTNULL", "x IS NOT NULL");
16217-
}
16207+
// Supported dialects consider `x NOTNULL` as an alias for `x IS NOT NULL`
16208+
let notnull_supported_dialects = all_dialects_where(|d| d.supports_notnull_operator());
16209+
let _ = notnull_supported_dialects.expr_parses_to("x NOTNULL", "x IS NOT NULL");
1621816210

16219-
#[test]
16220-
fn test_notnull_precedence() {
1622116211
// For dialects which support it, `NOT NULL NOTNULL` should
1622216212
// parse as `(NOT (NULL IS NOT NULL))`
16223-
let supported_dialects = all_dialects_where(|d| d.supports_notnull_operator());
16224-
let unsupported_dialects = all_dialects_except(|d| d.supports_notnull_operator());
16225-
1622616213
assert_matches!(
16227-
supported_dialects.expr_parses_to("NOT NULL NOTNULL", "NOT NULL IS NOT NULL"),
16214+
notnull_supported_dialects.expr_parses_to("NOT NULL NOTNULL", "NOT NULL IS NOT NULL"),
1622816215
Expr::UnaryOp {
1622916216
op: UnaryOperator::Not,
1623016217
..
1623116218
}
1623216219
);
1623316220

1623416221
// for unsupported dialects, parsing should stop at `NOT NULL`
16235-
unsupported_dialects.expr_parses_to("NOT NULL NOTNULL", "NOT NULL");
16222+
notnull_unsupported_dialects.expr_parses_to("NOT NULL NOTNULL", "NOT NULL");
1623616223
}

0 commit comments

Comments
 (0)