Skip to content

Commit 90a4ac6

Browse files
committed
Handle TEXT type modifiers across dialects
1 parent 36572d4 commit 90a4ac6

File tree

2 files changed

+27
-37
lines changed

2 files changed

+27
-37
lines changed

src/parser/mod.rs

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12170,20 +12170,13 @@ impl<'a> Parser<'a> {
1217012170
self.expect_token(&Token::RParen)?;
1217112171
Ok(DataType::FixedString(character_length))
1217212172
}
12173-
Keyword::TEXT => {
12174-
if dialect_is!(dialect is SnowflakeDialect) {
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-
}
12173+
Keyword::TEXT => match self.parse_optional_type_modifiers()? {
12174+
Some(modifiers) => Ok(DataType::Custom(
12175+
ObjectName::from(vec![Ident::new("TEXT")]),
12176+
modifiers,
12177+
)),
12178+
None => Ok(DataType::Text),
12179+
},
1218712180
Keyword::TINYTEXT => Ok(DataType::TinyText),
1218812181
Keyword::MEDIUMTEXT => Ok(DataType::MediumText),
1218912182
Keyword::LONGTEXT => Ok(DataType::LongText),
@@ -20213,7 +20206,7 @@ mod tests {
2021320206
use crate::ast::{
2021420207
CharLengthUnits, CharacterLength, DataType, ExactNumberInfo, ObjectName, TimezoneInfo,
2021520208
};
20216-
use crate::dialect::{AnsiDialect, GenericDialect, PostgreSqlDialect};
20209+
use crate::dialect::{AnsiDialect, GenericDialect, PostgreSqlDialect, SnowflakeDialect};
2021720210
use crate::test_utils::TestedDialects;
2021820211

2021920212
macro_rules! test_parse_data_type {
@@ -20416,6 +20409,24 @@ mod tests {
2041620409
);
2041720410
}
2041820411

20412+
#[test]
20413+
fn test_parse_text_with_length_as_custom_type() {
20414+
let dialect = TestedDialects::new(vec![
20415+
Box::new(GenericDialect {}),
20416+
Box::new(PostgreSqlDialect {}),
20417+
Box::new(SnowflakeDialect {}),
20418+
]);
20419+
20420+
test_parse_data_type!(
20421+
dialect,
20422+
"TEXT(16777216)",
20423+
DataType::Custom(
20424+
ObjectName::from(vec!["TEXT".into()]),
20425+
vec!["16777216".to_string()]
20426+
)
20427+
);
20428+
}
20429+
2041920430
#[test]
2042020431
fn test_ansii_exact_numeric_types() {
2042120432
// Exact numeric types: <https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#exact-numeric-type>

tests/sqlparser_snowflake.rs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5012,7 +5012,7 @@ fn test_select_dollar_column_from_stage() {
50125012
}
50135013

50145014
#[test]
5015-
fn test_parse_pg_style_cast_to_text_with_length() {
5015+
fn test_parse_cast_to_text_with_length() {
50165016
let select = snowflake().verified_only_select(
50175017
"SELECT _ID::TEXT(16777216) AS _ID FROM INCARE_ANALYTICS.USER_DETAILS",
50185018
);
@@ -5038,24 +5038,3 @@ fn test_parse_pg_style_cast_to_text_with_length() {
50385038
_ => unreachable!(),
50395039
}
50405040
}
5041-
5042-
#[test]
5043-
fn test_parse_cast_function_to_text_with_length() {
5044-
let select = snowflake().verified_only_select("SELECT CAST(_ID AS TEXT(42)) FROM USER_DETAILS");
5045-
match expr_from_projection(only(&select.projection)) {
5046-
Expr::Cast {
5047-
kind: CastKind::Cast,
5048-
data_type,
5049-
..
5050-
} => {
5051-
assert_eq!(
5052-
*data_type,
5053-
DataType::Custom(
5054-
ObjectName::from(vec![Ident::new("TEXT")]),
5055-
vec!["42".to_string()],
5056-
)
5057-
);
5058-
}
5059-
_ => unreachable!(),
5060-
}
5061-
}

0 commit comments

Comments
 (0)