Как я могу обновить json внутри list в Postgresql?

Рейтинг: 0Ответов: 0Опубликовано: 21.02.2023

У меня есть:

create table test(id serial, content jsonb);

insert into test(content) values ("[{"amount": 100, "userId": 1}, {"amount": 200, "userId": 2}]");

select * from test;
 id |                           content                            
----+-------------------------------------------------------------
  1 | [{"amount": 100, "userId": 1}, {"amount": 200, "userId": 2}]

Как я могу получить:

 id |                           content                            
----+-------------------------------------------------------------
  1 | [{"amount": 100, "userId": 1}, {"amount": 300, "userId": 2}]

Мне нужно обновить ключ amount где userId = 2 на 300. Как я могу это сделать?

Ответы

Ответов пока нет.