Skip to content

Commit 1a07c5d

Browse files
authored
accept JSON_TABLE both as an unquoted table name and a table-valued function (apache#1134)
1 parent d59b663 commit 1a07c5d

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/parser/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7515,7 +7515,11 @@ impl<'a> Parser<'a> {
75157515
with_offset,
75167516
with_offset_alias,
75177517
})
7518-
} else if self.parse_keyword(Keyword::JSON_TABLE) {
7518+
} else if matches!(
7519+
self.peek_token().token, Token::Word(w)
7520+
if w.keyword == Keyword::JSON_TABLE && self.peek_nth_token(1).token == Token::LParen
7521+
) {
7522+
self.expect_keyword(Keyword::JSON_TABLE)?;
75197523
self.expect_token(&Token::LParen)?;
75207524
let json_expr = self.parse_expr()?;
75217525
self.expect_token(&Token::Comma)?;

tests/sqlparser_postgres.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2328,6 +2328,21 @@ fn test_json() {
23282328
);
23292329
}
23302330

2331+
#[test]
2332+
fn parse_json_table_is_not_reserved() {
2333+
// JSON_TABLE is not a reserved keyword in PostgreSQL, even though it is in SQL:2023
2334+
// see: https://en.wikipedia.org/wiki/List_of_SQL_reserved_words
2335+
let Select { from, .. } = pg_and_generic().verified_only_select("SELECT * FROM JSON_TABLE");
2336+
assert_eq!(1, from.len());
2337+
match &from[0].relation {
2338+
TableFactor::Table {
2339+
name: ObjectName(name),
2340+
..
2341+
} => assert_eq!("JSON_TABLE", name[0].value),
2342+
other => panic!("Expected JSON_TABLE to be parsed as a table name, but got {other:?}"),
2343+
}
2344+
}
2345+
23312346
#[test]
23322347
fn test_composite_value() {
23332348
let sql = "SELECT (on_hand.item).name FROM on_hand WHERE (on_hand.item).price > 9";

0 commit comments

Comments
 (0)