PostgreSQL9.3:JSON 功能增强 根据PQ中文论坛francs 给出的东西结合自己的摸索总结下
| francs=> create table test_json1 (id serial primary key,name json);
CREATE TABLE
francs=> insert into test_json1 (name) values ('{"col1":1,"col2":"francs","col3":"male"}');
INSERT 0 1
francs=> insert into test_json1 (name) values ('{"col1":2,"col2":"fp","col3":"female"}');
INSERT 0 1
francs=> select * From test_json1;
id | name
----+------------------------------------------
1 | {"col1":1,"col2":"francs","col3":"male"}
2 | {"col1":2,"col2":"fp","col3":"female"}
(2 rows)
francs=> create table test_1 (id int4,name varchar(32),flag char(1));
CREATE TABLE
francs=> insert into test_1 values (1,'a','f');
INSERT 0 1
francs=> insert into test_1 values (2,'b','f');
INSERT 0 1
francs=> insert into test_1 values (3,'c','t');
INSERT 0 1
francs=> select * from test_1;
id | name | flag
----+------+------
1 | a | f
2 | b | f
3 | c | t
(3 rows)
|
备注:创建两张测试表,其中第一张为 json 表。
| francs=> select id ,name ->'col1' col1, name -> 'col2' col2, name -> 'col3' col3 from test_json1 where id=1;
id | col1 | col2 | col3
----+------+----------+--------
1 | 1 | "francs" | "male"
(1 row)
|
| francs=> select id ,name ->>'col1' col1, name ->> 'col2' col2, name ->> 'col3' col3 from test_json1 where id=1;
id | col1 | col2 | col3
----+------+--------+------
1 | 1 | francs | male
(1 row)
|
| francs=> select '{"a":[1,2,3],"b":[4,5,6]}'::json#>'{b,1}';
?column?
----------
5
(1 row)
francs=> select '{"a":[1,2,3],"b":[4,5,6]}'::json#>'{a,2}';
?column?
----------
3
(1 row)
|
| francs=> select * from test_json1 where id=1;
id | name
----+------------------------------------------
1 | {"col1":1,"col2":"francs","col3":"male"}
(1 row)
francs=> select * from json_each((select name from test_json1 where id=1));
key | value
------+----------
col1 | 1
col2 | "francs"
col3 | "male"
(3 rows)
francs=> select * from json_each('{"a":"foo", "b":"bar"}');
key | value
-----+-------
a | "foo"
b | "bar"
(2 rows)
|
| francs=> select * from json_each_text((select name from test_json1 where id=1));
key | value
------+--------
col1 | 1
col2 | francs
col3 | male
(3 rows)
|
| francs=> select row_to_json(test_1) from test_1;
row_to_json
--------------------------------
{"id":1,"name":"a","flag":"f"}
{"id":2,"name":"b","flag":"f"}
{"id":3,"name":"c","flag":"t"}
(3 rows)
francs=> select row_to_json(test_1) from test_1 where id=1;
row_to_json
--------------------------------
{"id":1,"name":"a","flag":"f"}
(1 row)
|
| francs=> alter table test_json1 add grade int4 default '6';
ALTER TABLE
francs=> select * from test_json1;
id | name | grade
----+------------------------------------------+-------
1 | {"col1":1,"col2":"francs","col3":"male"} | 6
2 | {"col1":2,"col2":"fp","col3":"female"} | 6
(2 rows)
francs=> select json_agg(name) from test_json1 group by grade;
json_agg
------------------------------------------------------------------------------------
[{"col1":1,"col2":"francs","col3":"male"}, {"col1":2,"col2":"fp","col3":"female"}]
(1 row)
|
备注:结果很明显。
| francs=> select * from test_1;
id | name | flag
----+------+------
1 | a | f
2 | b | f
3 | c | t
(3 rows)
francs=> select json_agg(a) from test_1 a;
json_agg
-----------------------------------
[{"id":1,"name":"a","flag":"f"}, +
{"id":2,"name":"b","flag":"f"}, +
{"id":3,"name":"c","flag":"t"}]
(1 row)
|
PostgreSQL9.3:JSON 功能增强 根据PQ中文论坛francs 给出的东西结合自己的摸索总结下的更多相关文章
- Java SE 5.0 - SE 8 的功能增强
Table of Contents 前言 Java 5.0 Generics Enhanced for Loop Autoboxing Typesafe Enums Varargs Static Im ...
- MWeb 1.4 新功能介绍二:静态博客功能增强
MWeb 比较有特色的是一键生成静态博客功能,然后从 MWeb 最开始规划要做静态博客生成功能时,我就希望 MWeb 的静态博客生成功能在易用的同时,还要有很强大的扩展性. 比如说能自己增加网站公告, ...
- VMare中安装“功能增强工具”,实现CentOS5.5与win7host共享文件夹的创建
读者如要转载,请标明出处和作者名,谢谢. 地址01:http://space.itpub.net/25851087 地址02:http://www.cnblogs.com/zjrodger/ 地址03 ...
- JSON取值(key是中文或者数字)方式详解
JSON取值(key是中文或者数字)方式详解 先准备一个json对象用于演示 var json = {'name':'zhangsan', '年龄':23, 404:'你可能迷路了'}; 使用JS中w ...
- Android 使用JSON格式与服务器交互 中文乱码问题解决
当前是在开发Android 程序时,客户端与服务器端采用JSON传送数据,发现中文乱码问题.不过这个问题的解决办法应该对所有java语言开发的项目都使用. 解决方法是: 1.客户端发送数据之间加上: ...
- jquery-7 jquery中的文档处理方法有哪些(方法的参数表示功能增强)
jquery-7 jquery中的文档处理方法有哪些(方法的参数表示功能增强) 一.总结 一句话总结:多看参考文档,多看主干目录.一般的功能分两个方法来实现,一个对应标签,一个对应标签和事情,比如克隆 ...
- Apache 后台服务器(主要处理php及一些功能请求 如:中文url) Nginx 前端服务器(利用它占用系统资源少得优势来处理静态页面大量请求) Lighttpd 图片服务器 总体来说,随着nginx功能得完善将使他成为今后web server得主流。
Apache 后台服务器(主要处理php及一些功能请求 如:中文url) Nginx 前端服务器(利用它占用系统资源少得优势来处理静态页面大量请求) Lighttpd 图片服务器 总体来说,随着ngi ...
- fastjson在将Map<Integer, String>转换成JSON字符串时,出现中文乱码问题
fastjson在将Map<Integer, String>转换成JSON字符串时,出现中文乱码问题. 先记下这个坑,改天在看看是怎么导致的,暂时通过避免使用Integer作为键(使用St ...
- DevExpress WPF v19.1:Data Grid/Tree List等控件功能增强
行业领先的.NET界面控件DevExpress 日前正式发布v19.1版本,本站将以连载的形式介绍各版本新增内容.在本系列文章中将为大家介绍DevExpress WPF v19.1中新增的一些控件及部 ...
随机推荐
- ETL概述 分类: H2_ORACLE 2013-08-23 10:36 344人阅读 评论(0) 收藏
转自:http://blog.csdn.net/leosoft/article/details/4279536 ETL,Extraction-Transformation-Loading的缩写,中文名 ...
- jquery-9 京东和酒仙网左侧导航如何实现
jquery-9 京东和酒仙网左侧导航如何实现 一.总结 一句话总结:布局的话多用定位,由底往上一层层的来布. 1.如何实现导航向div的平滑滑动? 右侧div和左侧的li一定要放在一起 127 &l ...
- 程序猿的还有一出路:大数据project师
非常多年前我非常郁闷地写了一篇博客<程序猿的出路在哪里?>,之所以郁闷.我记得是看了中国男足的比赛,不由自主对照自已苦逼的程序猿生涯,以前对中国软件的感情有如对中国男足,绝望到没有不论什么 ...
- 在线生成 QR Code
http://tool.oschina.net/qr 在线生成二维码(QR码)-采用ZXing与d-project
- Kinect舒适区范围--UE4 的Blueprint测试范例
本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接: http://blog.csdn.net/cartzhang/article/details/44748475 作者:ca ...
- [Angular] Scrolling the Message List To the Bottom Automatically Using OnChanges
Let's say the message list can Input (messages) from parent component, and what we want to do is whe ...
- 数据局部性(data locality)
信息处理的典型模式是,将所有数据项视为一个集合,并将其组织为适宜的数据结构(或者说使用适宜的数据结构对之进行存储以及组织),进而借助操作接口高效访问. 为了考查和评价各操作接口的效率,除了从最坏情况的 ...
- Struts2之配置使用
重要声明:此次学习struts2使用的版本号为:struts-2.3.15.3.假设是用的其它版本号出现的问题能够联系我. 一. 1.首先就是打开myeclipse创建project名为:struts ...
- js进阶 10-9 -of-type型子元素伪类选择器
js进阶 10-9 -of-type型子元素伪类选择器 一.总结 一句话总结:三种和first.last等有关的选择器. 1.:first和:first-child和:first-of-type的区别 ...
- .net core 微服务之Api网关(Api Gateway)
原文:.net core 微服务之Api网关(Api Gateway) 微服务网关目录 1. 微服务引子 2.使用Nginx作为api网关 3.自创api网关(重复轮子) 3.1.构建初始化 3.2. ...