Skip to content

Commit 2cc937c

Browse files
committed
fix :start and :end json accesses on snowflake
1 parent 2202e80 commit 2cc937c

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

src/parser/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5100,7 +5100,14 @@ impl<'a> Parser<'a> {
51005100
)?,
51015101
},
51025102
// Case when Snowflake Semi-structured data like key:value
5103-
Keyword::NoKeyword | Keyword::LOCATION | Keyword::TYPE | Keyword::DATE if dialect_of!(self is SnowflakeDialect | GenericDialect) => {
5103+
Keyword::NoKeyword
5104+
| Keyword::LOCATION
5105+
| Keyword::TYPE
5106+
| Keyword::DATE
5107+
| Keyword::START
5108+
| Keyword::END
5109+
if dialect_of!(self is SnowflakeDialect | GenericDialect) =>
5110+
{
51045111
Ok(Value::UnQuotedString(w.value))
51055112
}
51065113
_ => self.expected(

tests/sqlparser_snowflake.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,24 @@ fn parse_json_using_colon() {
229229
);
230230

231231
snowflake().one_statement_parses_to("SELECT a:b::int FROM t", "SELECT CAST(a:b AS INT) FROM t");
232+
233+
let sql = "SELECT a:start, a:end FROM t";
234+
let select = snowflake().verified_only_select(sql);
235+
assert_eq!(
236+
vec![
237+
SelectItem::UnnamedExpr(Expr::JsonAccess {
238+
left: Box::new(Expr::Identifier(Ident::new("a"))),
239+
operator: JsonOperator::Colon,
240+
right: Box::new(Expr::Value(Value::UnQuotedString("start".to_string()))),
241+
}),
242+
SelectItem::UnnamedExpr(Expr::JsonAccess {
243+
left: Box::new(Expr::Identifier(Ident::new("a"))),
244+
operator: JsonOperator::Colon,
245+
right: Box::new(Expr::Value(Value::UnQuotedString("end".to_string()))),
246+
})
247+
],
248+
select.projection
249+
);
232250
}
233251

234252
#[test]

0 commit comments

Comments
 (0)