Skip to content

Commit f2d4f91

Browse files
committed
accept JSON_TABLE both as an unquoted table name and a table-valued function
see apache#1123 (comment)
1 parent d59b663 commit f2d4f91

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2328,6 +2328,26 @@ 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+
match pg().verified_only_select("SELECT * FROM JSON_TABLE") {
2336+
Select { from, .. } => {
2337+
assert_eq!(1, from.len());
2338+
match &from[0].relation {
2339+
TableFactor::Table {
2340+
name: ObjectName(name),
2341+
..
2342+
} => {
2343+
assert_eq!("JSON_TABLE", name[0].value);
2344+
}
2345+
_ => unreachable!(),
2346+
}
2347+
}
2348+
}
2349+
}
2350+
23312351
#[test]
23322352
fn test_composite_value() {
23332353
let sql = "SELECT (on_hand.item).name FROM on_hand WHERE (on_hand.item).price > 9";

0 commit comments

Comments
 (0)