Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/dialect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions src/dialect/snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
19 changes: 19 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
Loading