This documentation is for the unreleased development version of jOOQ. Click on the above version links to get this documentation for a supported version of jOOQ.
JSON_REPLACE
Applies to ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
The MySQL style JSON_REPLACE
function is a function that does not add add (like JSON_INSERT) but replaces a value in a JSON document, given a JSON path.
SELECT JSON_REPLACE('{"a":1}', '$.a', 2), JSON_REPLACE('{"a":1}', '$.b', 2)
create.select( jsonReplace(val(json("{\"a\":1}")), "$.a", 2), jsonReplace(val(json("{\"a\":1}")), "$.b", 2)).fetch();
The result would look like this:
+--------------+--------------+ | json_replace | json_replace | +--------------+--------------+ | {"a":2} | {"a":1} | +--------------+--------------+
Dialect support
This example using jOOQ:
jsonReplace(val(json("{\"a\":1}")), "$.a", 2)
Translates to the following dialect specific expressions:
MariaDB, MySQL, SQLite
json_replace('{"a":1}', '$.a', 2)
Oracle
json_transform('{"a":1}', REPLACE '$.a' = 2)
SQLServer
CASE WHEN coalesce( json_query('{"a":1}', '$.a'), json_value('{"a":1}', '$.a') ) IS NULL THEN '{"a":1}' ELSE json_modify( json_modify('{"a":1}', '$.a', ''), ('strict ' + '$.a'), 2 ) END
ASE, Access, Aurora MySQL, Aurora Postgres, BigQuery, ClickHouse, CockroachDB, DB2, Derby, DuckDB, Exasol, Firebird, H2, HSQLDB, Hana, Informix, MemSQL, Postgres, Redshift, SQLDataWarehouse, Snowflake, Sybase, Teradata, Trino, Vertica, YugabyteDB
/* UNSUPPORTED */
Generated with jOOQ 3.20. Translate your own SQL on our website
Feedback
Do you have any feedback about this page? We'd love to hear it!