Skip to content

Commit 01fd20f

Browse files
Support the type key (#750)
1 parent bda8268 commit 01fd20f

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3822,7 +3822,7 @@ impl<'a> Parser<'a> {
38223822
)?,
38233823
},
38243824
// Case when Snowflake Semi-structured data like key:value
3825-
Keyword::NoKeyword | Keyword::LOCATION if dialect_of!(self is SnowflakeDialect | GenericDialect) => {
3825+
Keyword::NoKeyword | Keyword::LOCATION | Keyword::TYPE if dialect_of!(self is SnowflakeDialect | GenericDialect) => {
38263826
Ok(Value::UnQuotedString(w.value))
38273827
}
38283828
_ => self.expected(

tests/sqlparser_snowflake.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,28 @@ fn parse_json_using_colon() {
169169
select.projection[0]
170170
);
171171

172+
let sql = "SELECT a:type FROM t";
173+
let select = snowflake().verified_only_select(sql);
174+
assert_eq!(
175+
SelectItem::UnnamedExpr(Expr::JsonAccess {
176+
left: Box::new(Expr::Identifier(Ident::new("a"))),
177+
operator: JsonOperator::Colon,
178+
right: Box::new(Expr::Value(Value::UnQuotedString("type".to_string()))),
179+
}),
180+
select.projection[0]
181+
);
182+
183+
let sql = "SELECT a:location FROM t";
184+
let select = snowflake().verified_only_select(sql);
185+
assert_eq!(
186+
SelectItem::UnnamedExpr(Expr::JsonAccess {
187+
left: Box::new(Expr::Identifier(Ident::new("a"))),
188+
operator: JsonOperator::Colon,
189+
right: Box::new(Expr::Value(Value::UnQuotedString("location".to_string()))),
190+
}),
191+
select.projection[0]
192+
);
193+
172194
snowflake().one_statement_parses_to("SELECT a:b::int FROM t", "SELECT CAST(a:b AS INT) FROM t");
173195
}
174196

0 commit comments

Comments
 (0)