Paste this into a new question or an answer at dba.stackexchange.com:
<!-- --> > create table t (id int, data jsonb); > insert into t values > (1, '[ > {"id":"1","status":"test status1","updatedAt":"1571145003"}, > {"id":"2","status":"test status2","updatedAt":"1571145323"} > ]'); > > <pre> > ✓ > 1 rows affected > </pre> <!-- --> > with ct as > ( > select > id, ('{' || index-1 || ',updatedAt}')::text[] as path > from > t, > jsonb_array_elements(data) with ordinality arr(c, index) > ) > --select * from ct > --update t > --set data = jsonb_set(data, ct.path, '"1571150000"', false) > --from ct > --where ct.id = t.id; > > <pre> > ERROR: syntax error at end of input LINE 13: --where ct.id = t.id; ^ > </pre> <!-- --> > select * from t; > > <pre> > id | data > -: | :----------------------------------------------------------------------------------------------------------------------------------- > 1 | [{&quot;id&quot;: &quot;1&quot;, &quot;status&quot;: &quot;test status1&quot;, &quot;updatedAt&quot;: &quot;1571145003&quot;}, {&quot;id&quot;: &quot;2&quot;, &quot;status&quot;: &quot;test status2&quot;, &quot;updatedAt&quot;: &quot;1571145323&quot;}] > </pre> <!-- --> > with ct as > ( > select id, jsonb_array_elements(data) dt > from t > ) > , ct2 as > ( > select id, jsonb_set(dt, '{updatedAt}', '"1571150000"', false) dt2 > from ct > ) > update t > set data = (select jsonb_agg(dt2) from ct2 where ct2.id = t.id); > > > <pre> 1 rows affected > </pre> <!-- --> > select * from t; > > <pre> > id | data > -: | :----------------------------------------------------------------------------------------------------------------------------------- > 1 | [{&quot;id&quot;: &quot;1&quot;, &quot;status&quot;: &quot;test status1&quot;, &quot;updatedAt&quot;: &quot;1571150000&quot;}, {&quot;id&quot;: &quot;2&quot;, &quot;status&quot;: &quot;test status2&quot;, &quot;updatedAt&quot;: &quot;1571150000&quot;}] > </pre> *db<>fiddle [here](https://dbfiddle.uk/?rdbms=postgres_10&rdbms2=postgres_10&fiddle=349e15b2f5075d4d524a438e318618b1)*
back to fiddle