My database contains a table which has a column with jsonb type, and I want to update a part of these data using functions/operators from postgreSQL
The approach with jsonb_array_elements
and jsonb_set
was the right idea, but somehow you nested them the wrong way round:
UPDATE myTable SET myColumn = jsonb_set(myColumn, '{A}', (
SELECT jsonb_agg( element || '{"myArray":[]}' )
FROM jsonb_array_elements(myColumn -> 'A') element
));
(online demo)
Btw if your column already has jsonb
data type, you shouldn't need any casts.