Correct syntax to query JSON_SET in MYSQL in Node
P粉903052556
2023-08-31 20:22:09
<p>I need to set/update a JSON array in a MYSQL table from Node and I have this query which throws an <code>Invalid JSON path expression</code> error.
For example, I want to find the object with key <code>2022-01-03</code> and if it exists, update its value to <code>O 08:00</code></p>
<pre class="brush:php;toolbar:false;">UPDATE allemployees SET schedule = JSON_SET(schedule, '$.2022-01-03', 'O 08:00') WHERE name_cyr = 'John Doe' </pre>
<p>The JSON in my table is as follows:</p>
<pre class="brush:php;toolbar:false;">[{"2022-01-03": "H 08:00"}, [{"2022-01-04": " H 08:00"}] ]</pre></p>
https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=2c59600049b4dfc1675c444a6da578bb
Path
"2022-01-03"
contains dashes and must be enclosed in double quotes.The value to be set is not the superior value, but the component of the clear array element.