1 Answer
- Newest
- Most votes
- Most comments
0
【以下的回答经过翻译处理】 由于客户正在更新JSON文档中的值,因此只需使用内置的PostgreSQL JSON函数。
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)
Relevant content
- asked a year ago
- asked a year ago
- Accepted Answerasked 10 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago