2019独角兽企业重金招聘Python工程师标准>>>

Looking through the documentation for the Postgres 9.4 datatype JSONB, it is not immediately obvious to me how to do updates on JSONB columns.

Documentation for JSONB types and functions:

http://www.postgresql.org/docs/9.4/static/functions-json.htmlhttp://www.postgresql.org/docs/9.4/static/datatype-json.html

As an examples, I have this basic table structure:

CREATE TABLE test(id serial, data jsonb);

Inserting is easy, as in:

INSERT INTO test(data) values ('{"name": "my-name", "tags": ["tag1", "tag2"]}');

Now, how would I update the 'data' column? This is invalid syntax:

UPDATE test SET data->'name' = 'my-other-name' WHERE id = 1;

Is this documented somewhere obvious that I missed? Thanks.

答案======================

Ideally, you don't use JSON documents for data that you want to manage inside a relational database. Use a normalized relational design instead.

JSON is primarily intended to store whole documents that do not need to be manipulated inside the RDBMS.

Updating a row in Postgres always writes a new version of the whole row. That's the basic principle ofPostgres' MVCC model. From a performance perspective, it hardly matters whether you change a single piece of data inside a JSON object or all of it: a new version of the row has to be written.

Thus the advice in the manual:

JSON data is subject to the same concurrency-control considerations as any other data type when stored in a table. Although storing large documents is practicable, keep in mind that any update acquires a row-level lock on the whole row. Consider limiting JSON documents to a manageable size in order to decrease lock contention among updating transactions. Ideally, JSON documents should each represent an atomic datum that business rules dictate cannot reasonably be further subdivided into smaller datums that could be modified independently.

The gist of it: to modify anything inside a JSON object, you have to assign a modified object to the column. Postgres supplies limited means to build and manipulate json data in addition to its storage capabilities. The arsenal of tools has grown substantially with every new release since version 9.2. The upcoming version 9.4 is adding quite a bit.

Instructions how to work with the tools of Postgres 9.3:

  • How do I modify fields inside the new PostgreSQL JSON datatype?

答案2=========================

This is coming in 9.5 in the form of jsonb_set by Andrew Dunstan based on an existing extensionjsonbx that does work with 9.4

转载于:https://my.oschina.net/u/181793/blog/485200

perform update operations on columns of type JSONB相关推荐

  1. Java ResultSet教程

    Java ResultSet interface is a part of the java.sql package. It is one of the core components of the ...

  2. mangodb collection level operations

    2019独角兽企业重金招聘Python工程师标准>>> collection – Collection level operations Collection level utili ...

  3. 7月最新发布10.2.0.4.5 Patch Set Update

    同11.2.0.1.2 psu同时发布的还有10.2.0.4.5 psu,值得注意的是这2个psu都包括了针对ora-600/7445错误出现时信息显示的原因和调用(cause/action). 附该 ...

  4. Primavera P6 EPPM 19.12.X Patch/Update(补丁/更新)

    目录 Patch 19.12.18.0 Patch 19.12.17.0 Patch 19.12.16.0 Patch 19.12.15.0 Patch 19.12.14.0 Patch 19.12. ...

  5. Primavera P6 EPPM 21.12.X Patch/Update(补丁/更新)

    目录 目录 Patch 21.12.10.0 Patch 21.12.9.0 Patch 21.12.8.0 Patch 21.12.7.0 Patch 21.12.6.0 Patch 21.12.5 ...

  6. mysql columns表_mysql8 参考手册-INFORMATION_SCHEMA COLUMNS表

    COLUMNS表提供有关表中列的信息.相关 ST_GEOMETRY_COLUMNS表提供有关存储空间数据的表列的信息. 该COLUMNS表包含以下列: TABLE_CATALOG 包含该列的表所属的目 ...

  7. Primavera Unifier 19.12.X Patch/Update(补丁/更新)

    了解本文内容前,可以先读之前的关于patch的文章,希望可以给你带来帮助 Oracle Primavera P6 & Unifier等产品 Patch 补丁介绍_Oracle Primaver ...

  8. Postgres中jsonb类型

    Jsonb类型 PostgresSql支持两种JSON数据类型:json和jsonb.json类型以文本形式存储json对象,输入的文本是什么样的,存储的文本就是什么样的.每次处理时需要解析和分析文本 ...

  9. 几种多数据库表update的方式测试

    Created by Jerry Wang, last modified on Jun 13, 2014 假设有数据库表ZUPDATE_TEST1和ZUPDATE_TEST2 需要同时update,理 ...

最新文章

  1. R使用lm构建单变量线性回归模型
  2. WordPress 性能优化:为什么我的博客比你的快
  3. pythonsparkpickle_Learning Spark (Python版) 学习笔记(一)----RDD 基本概念与命令
  4. gzip与patch说明
  5. RealNetworks CTO:我们追求低复杂度的软解码
  6. mysql binlog过期策略_MySQL binlog日志优化方案
  7. C++获取一段算法程序耗时方法
  8. (18)System Verilog运算精度补齐示例
  9. 音视频开发(31)---H264 视频信息与压缩编码
  10. Linux下Socket网络编程send和recv使用注意事项
  11. 什么服务器有信号枪,绝地求生刺激战场8个必刷信号枪的时段地点
  12. 阶段3 3.SpringMVC·_03.SpringMVC常用注解_5 RequestHeader注解
  13. 外贸客户如何跟进?外贸客户类型及跟进策略
  14. otool nm工具命令收集
  15. 学校计算机比赛策划,学校计算机技能比赛活动策划方案
  16. 【老九】【Python】文件操作与异常处理
  17. php记录访问者ip和次数,一个能对访问者进行编号、记录访问次数、IP、时间的统计制作实例...
  18. 20亿美金独角兽Notion,和它在中国的“抄袭”者们
  19. gitlab页脚添加备案号
  20. Arduino 单总线驱动音频播放模块DY-SV 5W示例(MP3)

热门文章

  1. 线程同步--信号量内核对象
  2. 游戏是如何限制多开的,如何解决
  3. 大数据之-Hadoop之HDFS的API操作_文件IO流_下载_案例---大数据之hadoop工作笔记0064
  4. Uncaught (in promise) Error: timeout of 10000ms exceeded---SpringCloud Alibaba_若依微服务框架改造---工作笔记009
  5. ES6新特性_ES6箭头函数以及声明特点---JavaScript_ECMAScript_ES6-ES11新特性工作笔记009
  6. Unity3D引擎工作笔记0002---Unity3D 5下载安装
  7. JPA学习笔记---JPA理解---第一个JPA程序
  8. 批量修改图像命名方式
  9. 杭电2529Shot
  10. 随想录(被高估的busybox)