最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

sql - What is the use of '$' in the following MySql statements? - Stack Overflow

programmeradmin6浏览0评论

Looked through the docs, but didn't find an explanation of what exact purpose the $ is doing in the following lines of code:

Some code I found in our codebase:

set jsonData = JSON_ARRAY_APPEND(coalesce(jsonData, '[]'), '$',
                                 JSON_OBJECT('name', 'facility_id', 'old_value', '', 'new_value', NEW.facility_id));

and some code found in MySql docs:

mysql> SELECT JSON_ARRAY_APPEND(@j, '$[1]', 1);

Looked through the docs, but didn't find an explanation of what exact purpose the $ is doing in the following lines of code:

Some code I found in our codebase:

set jsonData = JSON_ARRAY_APPEND(coalesce(jsonData, '[]'), '$',
                                 JSON_OBJECT('name', 'facility_id', 'old_value', '', 'new_value', NEW.facility_id));

and some code found in MySql docs:

mysql> SELECT JSON_ARRAY_APPEND(@j, '$[1]', 1);
Share Improve this question edited Mar 21 at 13:57 Saba Iqbal 171 gold badge1 silver badge11 bronze badges asked Mar 19 at 19:02 ZacharyZachary 12 bronze badges 1
  • 3 JSON Path Syntax For paths used in MySQL JSON functions, the scope is always the document being searched or otherwise operated on, represented by a leading $ character. – Akina Commented Mar 19 at 19:33
Add a comment  | 

1 Answer 1

Reset to default -1

The $ symbol in MySQL JSON-related statements is used as a JSON path expression. JSON path expressions are used to specify the location of data within a JSON document. Here are the key details:

  • JSON Path Expression: The $ symbol represents the root of the JSON document. It is used to navigate within the JSON structure.

    ex:

    • set jsonData = JSON_ARRAY_APPEND(coalesce(jsonData, '[]'), '$', JSON_OBJECT('name', 'facility_id', 'old_value', '', 'new_value', NEW.facility_id));, -----> the $ symbol indicates that the new JSON object should be appended to the root array of the jsonData.

    • SELECT JSON_ARRAY_APPEND(@j, '$[1]', 1);, -----> the $[1] specifies the second element in the root array of the JSON document stored in the variable @j.

      For more info : MySQL JSON Functions Documentation

发布评论

评论列表(0)

  1. 暂无评论