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中新增的一些控件及部 ...
随机推荐
- ios开发网络学习AFN三:AFN的序列化
#import "ViewController.h" #import "AFNetworking.h" @interface ViewController () ...
- 使用DatagramSocket与DatagramPacket传输数据 分类: B1_JAVA 2013-10-12 13:00 1936人阅读 评论(0) 收藏
参考传智播客毕向东JAVA视频. 注: DatagramSocket发送的每个包都需要指定地址,而Socket则是在首次创建时指定地址,以后所有数据的发送都通过此socket. A socket is ...
- html css div img垂直居中
<head> <meta charset="UTF-8"> <meta name="Generator" content=&quo ...
- [Node.js] Build microservices in Node.js with micro
micro is a small module that makes it easy to write high performance and asynchronous microservices ...
- hdu5389 Zero Escape
Problem Description Zero Escape, is a visual novel adventure video game directed by Kotaro Uchikoshi ...
- transform、accumulate —— C++ 下的 MapReduce
accumulate:Map,逐元素分别单独处理: 注:for_each:不改变区间元素的内容,所以更多的是输出打印等功能: accumulate:Reduce,整体化归为一个单独的数值: 两个函数均 ...
- js实现去文本换行符小工具
js实现去文本换行符小工具 一.总结 一句话总结: 1.vertical属性使用的时候注意看清定义,也注意父元素的基准线问题.vertical-align:top; 2.获取textareaEleme ...
- 找不到头文件xxxxx.h file not found
项目里有该文件,但是还是显示找不到.或者是cocopods打开的项目. 原因:.h文件路径找不到.具体找不到的原因有很多种. 1.一般会设置 IOS引用三方framewrok的头文件出现'xxxxx/ ...
- Oracle数据库sqlplus与plsqldev解决乱码
(出现乱码 解决方法留存) 问题描述 : 在用eclipse使用jdbc插入中文数据的时,数据用plsqldev查询时,正常显示中文,但是用sqlplus查询时,为中文乱码,当用plsqldev直接插 ...
- webrtc 它android与PC互通
折腾了一个多星期,今天终将PC和android音频,视频全部打通. 到现在,android与android,pC与PC,android与PC之间已经解决了互通,的音频和视频是能够. 前段时间开了PC与 ...