Skip to content

Commit

Permalink
[plsql] Fix for #3646 -- removed warning "rule json_function contains…
Browse files Browse the repository at this point in the history
… an optional block with at least one alternative that can match an empty string" (#3648)

* Fix for #3646.

Until the Spec is fixed, remove the ?-operator on json_query_returning_clause.

* Add test of json_query_returning_clause.

* Add .tree file as proof.
  • Loading branch information
kaby76 authored Aug 9, 2023
1 parent 3831dea commit a77a447
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sql/plsql/PlSqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -6243,7 +6243,7 @@ json_function
| JSON_ARRAYAGG '(' expression (FORMAT JSON)? order_by_clause? json_on_null_clause? json_return_clause? STRICT? ')'
| JSON_OBJECT '(' json_object_content ')'
| JSON_OBJECTAGG '(' KEY? expression VALUE expression ((NULL_ | ABSENT) ON NULL_)? (RETURNING ( VARCHAR2 ('(' UNSIGNED_INTEGER ( BYTE | CHAR )? ')')? | CLOB | BLOB ))? STRICT? (WITH UNIQUE KEYS)?')'
| JSON_QUERY '(' expression (FORMAT JSON)? ',' CHAR_STRING json_query_returning_clause? json_query_wrapper_clause? json_query_on_error_clause? json_query_on_empty_clause? ')'
| JSON_QUERY '(' expression (FORMAT JSON)? ',' CHAR_STRING json_query_returning_clause json_query_wrapper_clause? json_query_on_error_clause? json_query_on_empty_clause? ')'
| JSON_SERIALIZE '(' CHAR_STRING (RETURNING json_query_return_type)? PRETTY? ASCII? TRUNCATE? ((NULL_ | ERROR | EMPTY (ARRAY | OBJECT)) ON ERROR)? ')'
| JSON_TRANSFORM '(' expression ',' json_transform_op (',' json_transform_op)* ')'
| JSON_VALUE '(' expression (FORMAT JSON)? (',' CHAR_STRING? json_value_return_clause? ((ERROR | NULL_ | DEFAULT literal)? ON ERROR)? ((ERROR | NULL_ | DEFAULT literal)? ON EMPTY)? json_value_on_mismatch_clause?')')?
Expand Down
8 changes: 8 additions & 0 deletions sql/plsql/examples/json_query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- From https://www.oratable.com/querying-json-data-in-oracle/
-- 2.2a SQL/JSON query: JSON_QUERY
-- to select the entire JSON document
select custid
, custname
, json_query(metadata, '$'
) json_metadata
from customer;
1 change: 1 addition & 0 deletions sql/plsql/examples/json_query.sql.tree
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(sql_script (unit_statement (data_manipulation_language_statements (select_statement (select_only_statement (subquery (subquery_basic_elements (query_block select (selected_list (select_list_elements (expression (logical_expression (unary_logical_expression (multiset_expression (relational_expression (compound_expression (concatenation (model_expression (unary_expression (atom (constant (quoted_string (variable_name (id_expression (regular_id custid)))))))))))))))) , (select_list_elements (expression (logical_expression (unary_logical_expression (multiset_expression (relational_expression (compound_expression (concatenation (model_expression (unary_expression (atom (constant (quoted_string (variable_name (id_expression (regular_id custname)))))))))))))))) , (select_list_elements (expression (logical_expression (unary_logical_expression (multiset_expression (relational_expression (compound_expression (concatenation (model_expression (unary_expression (standard_function (json_function json_query ( (expression (logical_expression (unary_logical_expression (multiset_expression (relational_expression (compound_expression (concatenation (model_expression (unary_expression (atom (constant (quoted_string (variable_name (id_expression (regular_id (non_reserved_keywords_in_12c metadata)))))))))))))))) , '$' json_query_returning_clause )))))))))))) (column_alias (identifier (id_expression (regular_id json_metadata)))))) (from_clause from (table_ref_list (table_ref (table_ref_aux (table_ref_aux_internal (dml_table_expression_clause (tableview_name (identifier (id_expression (regular_id customer))))))))))))))))) ; <EOF>)

0 comments on commit a77a447

Please sign in to comment.