Postgres lacks convenient operators for modifying JSON or JSONB values. A common operation one might want to do is to change one property in a JSON column across multiple rows, like:
UPDATE example SET json_col = json_col || '{ "prop": true }'::jsonb WHERE <conditions>;
The ||
operator is the natural choice for this because it is also used for array and jstore concatenation in Postgres.
This short PLV8 function adds the JSON concatenation operator. It is significantly more powerful than the array and hstore counterparts, and are capable of: