PG 数据库的增删查改

CREATE TABLE contact (
    id serial PRIMARY KEY,
    json_collection JSONB
);
INSERT INTO contact (json_collection) VALUES ('{"name": "value1", "sex": "value2"}');

更新旧数据并添加新字段数据

UPDATE contact
SET json_collection = jsonb_set(
    json_collection,
    '{age}',
    '"12"'
) || '{"phone": "17792434291"}'
WHERE id=1;

正常的更新旧数据

UPDATE contact
SET json_collection = jsonb_set(
    json_collection,
    '{age}',
    '"33"'
) WHERE id=1;

你可能感兴趣的:(PG)