1 回答
- 最新
- 投票最多
- 评论最多
0
Since the customer is updating a value in a JSON doc, just use the built in PostgreSQL JSON functions
postgres=> CREATE TABLE test_json (a int, b jsonb);
CREATE TABLE
postgres=> INSERT INTO test_json
postgres-> VALUES (1, '{"key1": "abc"}'), (2, '{"key1": "xyz"}');
INSERT 0 2
postgres=> UPDATE test_json
postgres-> SET b = jsonb_set(b, '{key1}', (upper((b->'key1')::text))::jsonb);
UPDATE 2
postgres=> SELECT * FROM test_json;
a | b
---+-----------------
1 | {"key1": "ABC"}
2 | {"key1": "XYZ"}
(2 rows)
已回答 4 年前
相关内容
- AWS 官方已更新 2 年前
- AWS 官方已更新 2 年前
- AWS 官方已更新 2 年前