我想更新我的jsonb字段,它存儲對象數組。 我想添加新的對象。如何在postgresql jsonb字段中追加對象,同時更新
CREATE TABLE justjson (id INTEGER, doc JSONB);
INSERT INTO justjson VALUES (1, '[
{
"name": "abc",
"age": "22"
},
{
"name": "def",
"age": "23"
}
]');
然後像價值
select doc from justjson;
doc
[{"age": "22", "name": "abc"}, {"age": "23", "name": "def"}]
現在,我想在這個jsonb
{"age": "45", "name": "xyz"}
如何更新此字段追加新的對象?
我的輸出如
doc
[{"age": "22", "name": "abc"}, {"age": "23", "name": "def"},{"age": "45", "name": "xyz"}]
[在這裏尋找](https://www.postgresql.org/ docs/current/static/functions-json.html)*將兩個jsonb值連接成一個新的jsonb值。* – klin