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中新增的一些控件及部 ...
随机推荐
- [Recompose] Lock Props using Recompose -- withProps
Learn how to use the ‘withProps’ higher order component to pre-fill a prop, unable to be overridden. ...
- 最全面的iOS和Mac开源项目和第三方库汇总
标签: UI 下拉刷新 EGOTableViewPullRefresh – 最早的下拉刷新控件. SVPullToRefresh – 下拉刷新控件. MJRefresh – 仅需一行代码就可以为UIT ...
- J2EE&JavaEE概述
来源 Sun公司在1998年发表JDK1.2版本的时候, 使用了新名称Java 2 Platform,即"Java2平台",修改后的JDK称为Java 2 Platform Sof ...
- php javascript的ajax
先说基础一点的get类型的ajax function loadXMLDoc() { var xmlhttp;//首先判断浏览器是否支持xmlhttprequest,因为ie56不是这个对象,是acti ...
- thinkphp3.1 缓存配置设置读取
以下黄字是我用的代码: //设置缓存名为zgg,内容为zongguagua,有效时间60秒 cache('zgg',"zongguagua",60); //读取缓存 if(cach ...
- IDEA使用从Eclipse过来的快捷键
1.Eclipse中的ctrl+shift+o --------> Ctrl + Alt + O 2.Eclipse中快捷键是Ctrl+O ---------> MacOS 下是 cmd+ ...
- STL map 按key值和按value值排序
map是用来存放<key, value>键值对的数据结构,能够非常方便高速的依据key查到对应的value. 假如存储水果和其单位价格.我们用map来进行存储就是个不错的选择. 我们这样定 ...
- LUA整合进MFC代码
这几天研究了一下lua,主要关注的是lua和vc之间的整合,把代码都写好放在VC宿主程序里,然后在lua里调用宿主程序的这些代码(或者叫接口.组件,随便你怎么叫),希望能用脚本来控制主程序的行为.这实 ...
- Qt 模仿QQ截图 动态吸附直线
最近在学Qt.学东西怎么能不动手. 就写了些小程序.看QQ截图能够动态吸附直线的功能挺有意思,所以就模仿了一个. 先上效果图 界面很简单..呵呵 移动鼠标,会把鼠标所在最小矩形选中.把没有选中的地方给 ...
- spring boot + gradle + mybatis
使用intelliJ创建 spring boot + gradle + mybatis站点 Spring boot作为快速入门是不错的选择,现在似乎没有看到大家写过spring boot + gr ...