Skip to content

Add JSON_SET() function #66120

@Hatlassian

Description

@Hatlassian

Feature request

StarRocks currently lacks a JSON_SET() function, which exists in MySQL and is very useful for manipulating JSON data.
Similar to this github issue but for JSON_SET() instead of JSON_REMOVE

Signature

JSON_SET(json_doc, path, val[, path, val] ...)

Behavior

Mostly copied from docs here

  • Inserts or updates data in a JSON document at one or more specified JSON paths.
  • Returns NULL if any argument is NULL.
  • Path-value pairs are evaluated from left to right. The document produced by evaluating one pair becomes th enew value against which the next pair is evaluated.
  • Throws an error if the json_doc argument is not a valid JSON document or any path argument is not a valid expression, or contains a * or ** wildcard.
  • Returns the modified JSON document as a string.
  • Follows MySQL path syntax (e.g., .a, [0]).

Examples

-- Replace element 'a' and insert element 'c'.
SELECT JSON_SET('{ "a": 1, "b": [2, 3]}', '$.a', 10, '$.c', '[true, false]');
-- Expected result: {"a": 10, "b": [2, 3], "c": "[true, false]"}

Reference

https://dev.mysql.com/doc/refman/8.4/en/json-modification-functions.html#function_json-set

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions