I would like to update fields of the following JSON array (stored in a column with JSONB datatype) based on the objectId.
[
{
objectId: 'gDKn1jM5d',
objectType: 'type1',
posX: 50,
posY: 100,
},
{
objectId: '4dg5E8BDv',
objectType: 'type2',
posX: 50,
posY: 100,
},
{
objectId: 'ZmCwOf5N2',
objectType: 'type3',
posX: 100,
posY: 150,
}
]
In Mongodb I can use a simple update statement but I was not able to find a way in postgres.
For example I would like to update all array elements with objectId 'ZmCwOf5N2' to the posX value 300 (that means it would only affect the 3rd array item).
I'm looking for a plain SQL statement in order to execute the update. The postgres version is 11.
It is not possible for me to install extensions because I'm using a database as a service provider. However, in case there is no easy way to accomplish the update statement, I would be able to add a postgres function using e.g. C code.