Dev Helpers

SQL / JSON construction

Replace the middle coordinate

Dev Helpers · November 14, 2025

Replacing a JSON array element requires an existing path. A missing coordinate calls for a separate insert or set policy.

Worked example

SELECT json_replace('[2,4,8]','$[1]',6) AS point;

Result

[
  {
    "point": "[2,6,8]"
  }
]

Implementation notes

JSON functions return a new value. Updating a stored document also requires an UPDATE statement targeting the intended row.

Try it yourself

Try a three-element vector and a shorter vector with the same update path.

Open the SQL example →

Editorial date November 14, 2025 · Published December 6, 2026

Related articles

Construct an array

A JSON array preserves element order and type. Inspect the distinction between a nested JSON value and a string containing JSON text.

Compare two literal lists

Set operations compare rows under SQL's rules for duplicates. Check whether the result represents membership or the number of occurrences.