表结构及数据
--按jsonb字段 作为查询条件
SELECT * FROM person WHERE info::jsonb->>'age' = '30';
--按jsob字段排序
SELECT * FROM person ORDER BY info::jsonb->>'age' DESC;
--根据jsonb 中属性更新 非jsonb 字段
UPDATE person SET id = '4' WHERE info::jsonb->> 'name'='张三';
--根据jsonb字段 更新jsonb字段 增量更新
UPDATE person SET info = (info::jsonb||'{"name":"zhangsan三"}') WHERE info::jsonb->> 'name'='张三';
更新jsonb类型里面的数据
UPDATE pg_hs_info_20170415
SET pg_ext = JSONB_set (
pg_ext,
'{FWZL}',
to_jsonb (pg_fwzl)
)
WHERE
pg_ext :: JSON ->> 'FWZL' != pg_fwzl;
SET pg_ext = JSONB_set (
pg_ext,
'{FWZL}',
to_jsonb (pg_fwzl)
)
WHERE
pg_ext :: JSON ->> 'FWZL' != pg_fwzl;