Skip to content

Commit

Permalink
accept JSON_TABLE both as an unquoted table name and a table-valued f…
Browse files Browse the repository at this point in the history
…unction

see apache#1123 (comment)
  • Loading branch information
lovasoa committed Feb 14, 2024
1 parent d59b663 commit f2d4f91
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7515,7 +7515,11 @@ impl<'a> Parser<'a> {
with_offset,
with_offset_alias,
})
} else if self.parse_keyword(Keyword::JSON_TABLE) {
} else if matches!(
self.peek_token().token, Token::Word(w)
if w.keyword == Keyword::JSON_TABLE && self.peek_nth_token(1).token == Token::LParen
) {
self.expect_keyword(Keyword::JSON_TABLE)?;
self.expect_token(&Token::LParen)?;
let json_expr = self.parse_expr()?;
self.expect_token(&Token::Comma)?;
Expand Down
20 changes: 20 additions & 0 deletions tests/sqlparser_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2328,6 +2328,26 @@ fn test_json() {
);
}

#[test]
fn parse_json_table_is_not_reserved() {
// JSON_TABLE is not a reserved keyword in PostgreSQL, even though it is in SQL:2023
// see: https://en.wikipedia.org/wiki/List_of_SQL_reserved_words
match pg().verified_only_select("SELECT * FROM JSON_TABLE") {

Check failure on line 2335 in tests/sqlparser_postgres.rs

View workflow job for this annotation

GitHub Actions / lint

this match could be written as a `let` statement
Select { from, .. } => {
assert_eq!(1, from.len());
match &from[0].relation {
TableFactor::Table {
name: ObjectName(name),
..
} => {
assert_eq!("JSON_TABLE", name[0].value);
}
_ => unreachable!(),
}
}
}
}

#[test]
fn test_composite_value() {
let sql = "SELECT (on_hand.item).name FROM on_hand WHERE (on_hand.item).price > 9";
Expand Down

0 comments on commit f2d4f91

Please sign in to comment.