Correct syntax to query JSON_SET in MYSQL in Node
P粉903052556
P粉903052556 2023-08-31 20:22:09
0
1
491
<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>
P粉903052556
P粉903052556

reply all(1)
P粉851401475
UPDATE allemployees
SET schedule = JSON_SET(schedule, '$[0]."2022-01-03"', 'O 08:00') 
WHERE name_cyr = 'John Doe';

https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=2c59600049b4dfc1675c444a6da578bb

  1. Path"2022-01-03" contains dashes and must be enclosed in double quotes.

  2. The value to be set is not the superior value, but the component of the clear array element.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template