我有成千上万条这样的记录(列名是“详细信息”):
"name": "ROSE", "role": "CHEW", "state": "Texas", "surname":
"OBAMA", "addresses": {"msisdn": {"0123456": {}}},
"facility_name": "Texas_Hospital", "receiver_role": "health care
worker", "personnel_code": "99999", "default_addr_type": "msisdn",
"preferred_language": "eng_NG", "uniqueid_field_name":
"personnel_code", "uniqueid_field_length": "5"
现在,我需要在德克萨斯州的每个医护人员的人事代码后加上星号(例如,“ 99999 *”),以便外部应用程序将其跳过。
我可以通过以下方法一个接一个地更改它们:
update identities_identity SET details =
JSONB_set(details,'{personnel_code}', to_jsonb('99999*'::text)) where
identities_identity.details->>'name' like 'ROSE';
但是非常麻烦,因为数据库中有数百个。
有没有一种方法可以使该过程自动化,因此只需在与该表达式匹配的每个代码中添加一个星号(成为德克萨斯州的每个医护人员)
[列名是详细信息] [数据库是identities_identity]
谢谢
答案 0 :(得分:2)
您快到了:
UPDATE identities_identity
SET details = jsonb_set(
details,
'{personnel_code}',
to_jsonb(details->>'personnel_code' || '*')
)
WHERE details->>'state' = 'Texas';