diff --git a/src/dialect/mod.rs b/src/dialect/mod.rs index fed81b60a..ab92ff83f 100644 --- a/src/dialect/mod.rs +++ b/src/dialect/mod.rs @@ -1418,6 +1418,16 @@ pub trait Dialect: Debug + Any { false } + /// Returns true if the dialect supports parenthesized modifiers for the `TEXT` data type. + /// + /// Example: + /// ```sql + /// SELECT col::TEXT(16777216) + /// ``` + fn supports_text_type_modifiers(&self) -> bool { + false + } + /// Returns true if the dialect supports the `INTERVAL` data type with [Postgres]-style options. /// /// Examples: diff --git a/src/dialect/snowflake.rs b/src/dialect/snowflake.rs index 1ac21d007..31b86e1ac 100644 --- a/src/dialect/snowflake.rs +++ b/src/dialect/snowflake.rs @@ -235,6 +235,11 @@ impl Dialect for SnowflakeDialect { true } + /// See [doc](https://docs.snowflake.com/en/sql-reference/data-types-text) + fn supports_text_type_modifiers(&self) -> bool { + true + } + /// See [doc](https://docs.snowflake.com/en/sql-reference/constructs/from) fn supports_parens_around_table_factor(&self) -> bool { true diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 6282ed3d7..01a0d2a81 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -12170,7 +12170,20 @@ impl<'a> Parser<'a> { self.expect_token(&Token::RParen)?; Ok(DataType::FixedString(character_length)) } - Keyword::TEXT => Ok(DataType::Text), + Keyword::TEXT => { + if dialect.supports_text_type_modifiers() { + if let Some(modifiers) = self.parse_optional_type_modifiers()? { + Ok(DataType::Custom( + ObjectName::from(vec![Ident::new("TEXT")]), + modifiers, + )) + } else { + Ok(DataType::Text) + } + } else { + Ok(DataType::Text) + } + } Keyword::TINYTEXT => Ok(DataType::TinyText), Keyword::MEDIUMTEXT => Ok(DataType::MediumText), Keyword::LONGTEXT => Ok(DataType::LongText), diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index 17f368bbb..781e45ded 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -6567,6 +6567,25 @@ fn interval_disallow_interval_expr_double_colon() { ) } +#[test] +fn parse_text_type_modifier_double_colon_cast() { + let dialects = all_dialects_where(|d| d.supports_text_type_modifiers()); + let expr = dialects.verified_expr("_ID::TEXT(16777216)"); + assert_eq!( + expr, + Expr::Cast { + kind: CastKind::DoubleColon, + expr: Box::new(Expr::Identifier(Ident::new("_ID"))), + data_type: DataType::Custom( + ObjectName::from(vec![Ident::new("TEXT")]), + vec!["16777216".to_string()] + ), + array: false, + format: None, + } + ); +} + #[test] fn parse_interval_and_or_xor() { let sql = "SELECT col FROM test \