Postgresql更新JSON字段中某一个值的SQL语句

299 阅读1分钟
  1. 方法一,使用jsonb_set方法:
update menus
set meta = meta || jsonb_set(meta, '{order}', '1') || jsonb_set(meta, '{title}', '"标题"')
where id = 1;
  1. 方法二,使用jsonb_build_object 构建多个JSON值:
update menus
set meta = meta || jsonb_build_object('order', '2', 'title', '标题1')
where id = 1;