Skip to content

Commit

Permalink
snowflake: OBJECT constants might rely on expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
lustefaniak committed Dec 20, 2023
1 parent ca6b5da commit 8302d04
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/ast/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use bigdecimal::BigDecimal;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

use crate::ast::Expr;
#[cfg(feature = "visitor")]
use sqlparser_derive::{Visit, VisitMut};

Expand All @@ -28,7 +29,7 @@ use sqlparser_derive::{Visit, VisitMut};
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub struct ObjectConstantKeyValue {
pub key: String,
pub value: Value,
pub value: Box<Expr>,
}

/// Primitive SQL values such as number and string
Expand Down
2 changes: 1 addition & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4955,7 +4955,7 @@ impl<'a> Parser<'a> {
loop {
let key = self.parse_literal_string()?;
self.expect_token(&Token::Colon)?;
let value = self.parse_value()?;
let value = Box::new(self.parse_expr()?);
fields.push(ObjectConstantKeyValue { key, value });
if !self.consume_token(&Token::Comma) {
break;
Expand Down
5 changes: 5 additions & 0 deletions tests/sqlparser_snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,11 @@ fn parse_object_constants() {
snowflake().verified_stmt("UPDATE my_table SET my_object = OBJECT_CONSTRUCT('Alberta', 'Edmonton', 'Manitoba', 'Winnipeg')");
}

#[test]
fn parse_object_constants_expr() {
snowflake().verified_stmt("SELECT { 'foo': bar.baz } AS r FROM tbl AS bar");
}

#[test]
fn parse_array_index_json_dot() {
let stmt = snowflake().verified_only_select("SELECT src[0].order_number FROM car_sales");
Expand Down

0 comments on commit 8302d04

Please sign in to comment.