Skip to content

Commit

Permalink
Fix(oracle): make parentheses in JSON_TABLE's COLUMNS clause optional
Browse files Browse the repository at this point in the history
  • Loading branch information
georgesittas committed Sep 12, 2023
1 parent 12db377 commit b9f5ede
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sqlglot/dialects/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,12 @@ def _parse_json_table(self) -> exp.JSONTable:
path = self._match(TokenType.COMMA) and self._parse_string()
error_handling = self._parse_on_handling("ERROR", "ERROR", "NULL")
empty_handling = self._parse_on_handling("EMPTY", "ERROR", "NULL")

self._match(TokenType.COLUMN)
expressions = self._parse_wrapped_csv(self._parse_json_column_def)
l_paren = self._match(TokenType.L_PAREN)
expressions = self._parse_csv(self._parse_json_column_def)
if l_paren:
self._match_r_paren()

return exp.JSONTable(
this=this,
Expand Down
4 changes: 4 additions & 0 deletions tests/dialects/test_oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ def test_json_table(self):
self.validate_identity(
"SELECT * FROM JSON_TABLE(foo FORMAT JSON, 'bla' ERROR ON ERROR NULL ON EMPTY COLUMNS (foo PATH 'bar'))"
)
self.validate_identity(
"SELECT * FROM JSON_TABLE(foo FORMAT JSON, 'bla' ERROR ON ERROR NULL ON EMPTY COLUMNS foo PATH 'bar')",
"SELECT * FROM JSON_TABLE(foo FORMAT JSON, 'bla' ERROR ON ERROR NULL ON EMPTY COLUMNS (foo PATH 'bar'))",
)
self.validate_identity(
"""SELECT
CASE WHEN DBMS_LOB.GETLENGTH(info) < 32000 THEN DBMS_LOB.SUBSTR(info) END AS info_txt,
Expand Down

0 comments on commit b9f5ede

Please sign in to comment.