Puede hacerlo con una combinación de jsonb
funciones y operadores
:
UPDATE company c
SET log = sub.log2
FROM (
SELECT *
FROM company c
CROSS JOIN LATERAL (
SELECT jsonb_agg(jsonb_set(l, '{oldvalue}', to_jsonb(rtrim(l->>'oldvalue')))) AS log2
FROM jsonb_array_elements(c.log) l
) sub
WHERE jsonb_typeof(log) = 'array' -- exclude NULL and non-arrays
) sub
WHERE c.code = sub.code -- assuming code is unique
AND c.log <> sub.log2; -- only where column actually changed.