Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrain JSON_TABLE table function parsing to MySqlDialect and AnsiDialect #1123

Closed
wants to merge 19 commits into from
Closed
4 changes: 3 additions & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7506,7 +7506,9 @@ impl<'a> Parser<'a> {
with_offset,
with_offset_alias,
})
} else if self.parse_keyword(Keyword::JSON_TABLE) {
} else if dialect_of!(self is MySqlDialect | AnsiDialect)
&& self.parse_keyword(Keyword::JSON_TABLE)
{
self.expect_token(&Token::LParen)?;
let json_expr = self.parse_expr()?;
self.expect_token(&Token::Comma)?;
Expand Down
21 changes: 21 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8407,3 +8407,24 @@ fn test_buffer_reuse() {
p.parse_statements().unwrap();
let _ = p.into_tokens();
}

#[test]
fn parse_json_table_err() {
let unsupported_dialects =
all_dialects_except(|d| d.is::<AnsiDialect>() || d.is::<MySqlDialect>());

// JSON_TABLE table function is not supported in the above dialects.
assert!(unsupported_dialects
.parse_sql_statements("SELECT * FROM JSON_TABLE('[[1, 2], [3, 4]]', '$[*]' COLUMNS(a INT PATH '$[0]', b INT PATH '$[1]')) AS t")
.is_err());
}

#[test]
fn parse_json_table_as_identifier() {
let supported_dialects =
all_dialects_except(|d| d.is::<AnsiDialect>() || d.is::<MySqlDialect>());

assert!(supported_dialects
.parse_sql_statements("SELECT * FROM json_table")
.is_ok());
}
Loading