File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1451,6 +1451,16 @@ pub trait Dialect: Debug + Any {
14511451 false
14521452 }
14531453
1454+ /// Returns true if the dialect supports parenthesized modifiers for the `TEXT` data type.
1455+ ///
1456+ /// Example:
1457+ /// ```sql
1458+ /// SELECT col::TEXT(16777216)
1459+ /// ```
1460+ fn supports_text_type_modifiers ( & self ) -> bool {
1461+ false
1462+ }
1463+
14541464 /// Returns true if the dialect supports the `INTERVAL` data type with [Postgres]-style options.
14551465 ///
14561466 /// Examples:
Original file line number Diff line number Diff line change @@ -235,6 +235,11 @@ impl Dialect for SnowflakeDialect {
235235 true
236236 }
237237
238+ /// See [doc](https://docs.snowflake.com/en/sql-reference/data-types-text)
239+ fn supports_text_type_modifiers ( & self ) -> bool {
240+ true
241+ }
242+
238243 /// See [doc](https://docs.snowflake.com/en/sql-reference/constructs/from)
239244 fn supports_parens_around_table_factor ( & self ) -> bool {
240245 true
Original file line number Diff line number Diff line change @@ -12555,7 +12555,20 @@ impl<'a> Parser<'a> {
1255512555 self.expect_token(&Token::RParen)?;
1255612556 Ok(DataType::FixedString(character_length))
1255712557 }
12558- Keyword::TEXT => Ok(DataType::Text),
12558+ Keyword::TEXT => {
12559+ if dialect.supports_text_type_modifiers() {
12560+ if let Some(modifiers) = self.parse_optional_type_modifiers()? {
12561+ Ok(DataType::Custom(
12562+ ObjectName::from(vec![Ident::new("TEXT")]),
12563+ modifiers,
12564+ ))
12565+ } else {
12566+ Ok(DataType::Text)
12567+ }
12568+ } else {
12569+ Ok(DataType::Text)
12570+ }
12571+ }
1255912572 Keyword::TINYTEXT => Ok(DataType::TinyText),
1256012573 Keyword::MEDIUMTEXT => Ok(DataType::MediumText),
1256112574 Keyword::LONGTEXT => Ok(DataType::LongText),
Original file line number Diff line number Diff line change @@ -6586,6 +6586,25 @@ fn interval_disallow_interval_expr_double_colon() {
65866586 )
65876587}
65886588
6589+ #[test]
6590+ fn parse_text_type_modifier_double_colon_cast() {
6591+ let dialects = all_dialects_where(|d| d.supports_text_type_modifiers());
6592+ let expr = dialects.verified_expr("_ID::TEXT(16777216)");
6593+ assert_eq!(
6594+ expr,
6595+ Expr::Cast {
6596+ kind: CastKind::DoubleColon,
6597+ expr: Box::new(Expr::Identifier(Ident::new("_ID"))),
6598+ data_type: DataType::Custom(
6599+ ObjectName::from(vec![Ident::new("TEXT")]),
6600+ vec!["16777216".to_string()]
6601+ ),
6602+ array: false,
6603+ format: None,
6604+ }
6605+ );
6606+ }
6607+
65896608#[test]
65906609fn parse_interval_and_or_xor() {
65916610 let sql = "SELECT col FROM test \
You can’t perform that action at this time.
0 commit comments