Skip to content

Commit 435b2e0

Browse files
committed
Snowflake: Add support for text data type modifiers
1 parent 913cf0e commit 435b2e0

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

src/dialect/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,16 @@ pub trait Dialect: Debug + Any {
14181418
false
14191419
}
14201420

1421+
/// Returns true if the dialect supports parenthesized modifiers for the `TEXT` data type.
1422+
///
1423+
/// Example:
1424+
/// ```sql
1425+
/// SELECT col::TEXT(16777216)
1426+
/// ```
1427+
fn supports_text_type_modifiers(&self) -> bool {
1428+
false
1429+
}
1430+
14211431
/// Returns true if the dialect supports the `INTERVAL` data type with [Postgres]-style options.
14221432
///
14231433
/// Examples:

src/dialect/snowflake.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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

src/parser/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12170,7 +12170,20 @@ impl<'a> Parser<'a> {
1217012170
self.expect_token(&Token::RParen)?;
1217112171
Ok(DataType::FixedString(character_length))
1217212172
}
12173-
Keyword::TEXT => Ok(DataType::Text),
12173+
Keyword::TEXT => {
12174+
if dialect.supports_text_type_modifiers() {
12175+
if let Some(modifiers) = self.parse_optional_type_modifiers()? {
12176+
Ok(DataType::Custom(
12177+
ObjectName::from(vec![Ident::new("TEXT")]),
12178+
modifiers,
12179+
))
12180+
} else {
12181+
Ok(DataType::Text)
12182+
}
12183+
} else {
12184+
Ok(DataType::Text)
12185+
}
12186+
}
1217412187
Keyword::TINYTEXT => Ok(DataType::TinyText),
1217512188
Keyword::MEDIUMTEXT => Ok(DataType::MediumText),
1217612189
Keyword::LONGTEXT => Ok(DataType::LongText),

tests/sqlparser_common.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6567,6 +6567,25 @@ fn interval_disallow_interval_expr_double_colon() {
65676567
)
65686568
}
65696569

6570+
#[test]
6571+
fn parse_text_type_modifier_double_colon_cast() {
6572+
let dialects = all_dialects_where(|d| d.supports_text_type_modifiers());
6573+
let expr = dialects.verified_expr("_ID::TEXT(16777216)");
6574+
assert_eq!(
6575+
expr,
6576+
Expr::Cast {
6577+
kind: CastKind::DoubleColon,
6578+
expr: Box::new(Expr::Identifier(Ident::new("_ID"))),
6579+
data_type: DataType::Custom(
6580+
ObjectName::from(vec![Ident::new("TEXT")]),
6581+
vec!["16777216".to_string()]
6582+
),
6583+
array: false,
6584+
format: None,
6585+
}
6586+
);
6587+
}
6588+
65706589
#[test]
65716590
fn parse_interval_and_or_xor() {
65726591
let sql = "SELECT col FROM test \

0 commit comments

Comments
 (0)