postgresql - Postgres jsonb_set 连接当前值
问题描述
我正在尝试使用 jsonb_set 来更新我的数据库中的一系列 json 对象。我可以获得一个使用字符串值更新对象的查询,但是我似乎无法使用当前值更新它。
UPDATE entity
SET properties = jsonb_set(properties, '{c_number}', concat('0', properties->>'c_number'))
WHERE type = 1 and length(properties->>'c_number') = 7
以上不适用于当前格式,我认为问题出properties->>'c_number'
在 jsonb_set 内部。有没有办法可以访问当前值并简单地添加前导 0?
解决方案
找到了解决方案:
UPDATE entity
SET properties = jsonb_set(properties, '{c_number}', concat('"0', properties->>'c_number', '"')::jsonb)
WHERE type = 1 and length(properties->>'c_number') = 7
推荐阅读
- angular - 创建组件的多个实例时多次订阅调用
- reactjs - 工具提示的条件渲染似乎无法正常工作
- swift - 无法在 ARKit 中查看 SKVideo
- python - 如何将绘图与其他 HTML 内容一起导出为 pdf?
- java - Kotlin 协程单元测试执行异常
- amazon-web-services - 如何将 Aurora Mysql ddl 翻译成 Redshift ddl
- python - 如何计算python中2个日期时间之间的差异
- python - 您可以在本地计算机上运行 Google Colab 吗?
- python - 为 4 个数组类型的观察设置观察空间
- webrtc - 如何使用 PeerJS 实现多方 P2P 视频会议?