XuQianJin-Stars opened a new pull request #1143: [CALCITE-2884] Add the 
JSON_INSERT,JSON_REPLACE,JSON_SET function
URL: https://github.com/apache/calcite/pull/1143
 
 
   `JSON_INSERT`(jsondoc, path, val[, path, val] )
   
   `JSON_REPLACE`(jsondoc, _path_, _val_[, path, val] )
   
   `JSON_SET`(jsondoc, path, _val[, path, val] )
   
   Inserts data into a JSON document and returns the result. Returns {{NULL}} 
if any argument is {{NULL}}. An error occurs if the _{{json_doc}}_ argument is 
not a valid JSON document or any _{{path}}_ argument is not a valid path 
expression or contains a  *or {{}}}}*{{{{*}} wildcard.
   
   The path-value pairs are evaluated left to right. The document produced by 
evaluating one pair becomes the new value against which the next pair is 
evaluated.
   
   A path-value pair for an existing path in the document is ignored and does 
not overwrite the existing document value. A path-value pair for a nonexisting 
path in the document adds the value to the document if the path identifies one 
of these types of values:
    * A member not present in an existing object. The member is added to the 
object and associated with the new value.
   
    * A position past the end of an existing array. The array is extended with 
the new value. If the existing value is not an array, it is autowrapped as an 
array, then extended with the new value.
   
   Otherwise, a path-value pair for a nonexisting path in the document is 
ignored and has no effect.
   
   For a comparison of 
[JSON_INSERT()](https://dev.mysql.com/doc/refman/5.7/en/json-modification-functions.html#function_json-insert),
 
[JSON_REPLACE()](https://dev.mysql.com/doc/refman/5.7/en/json-modification-functions.html#function_json-replace),
 and 
[JSON_SET()](https://dev.mysql.com/doc/refman/5.7/en/json-modification-functions.html#function_json-set),
 see the discussion of 
[JSON_SET()](https://dev.mysql.com/doc/refman/5.7/en/json-modification-functions.html#function_json-set).
   
   JSON_INSERT SQL:
   
   ```
   SELECT JSON_INSERT(v, '$.a', 10, '$.c', '[true, false]') AS c1
    FROM (VALUES ('{ "a": 1, "b": [2, 3]}')) AS t(v);
   ```
   
   Result:
   
   | c1                                          |
   | ------------------------------------------- |
   | {"a": 1, "b": [2, 3], "c": "[true, false]"} |
   
   JSON_REPLACE SQL:
   
   ```
   SELECT JSON_REPLACE(v, '$.a', 10, '$.c', '[true, false]') AS c1
    FROM (VALUES ('{ "a": 1, "b": [2, 3]}')) AS t(v);
   ```
   
   Result:
   
   | c1                      |
   | ----------------------- |
   | {"a": 10, "b": [2, 3],} |
   
   JSON_SET SQL:
   
   ```
   SELECT JSON_INSERT(v, '$.a', 10, '$.c', '[true, false]') AS c1
    FROM (VALUES ('{ "a": 1, "b": [2, 3]}')) AS t(v);
   ```
   
   Result:
   
   | c1                                           |
   | -------------------------------------------- |
   | {"a": 10, "b": [2, 3], "c": "[true, false]"} |
   
   
   
    

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to