Postgresql - jsonb_pretty & dateStyle
1.
SHOW datestyle;
DateStyle
-----------
ISO, MDY
(1 row)
INSERT INTO container VALUES ('13/01/2010');
ERROR: date/time field value out of range: "13/01/2010"
HINT: Perhaps you need a different "datestyle" setting.
SET datestyle = "ISO, DMY";
SET
INSERT INTO container VALUES ('13/01/2010');
INSERT 0 1
SET datestyle = default;
SET
------------------------------------------------
2.
--http://www.silota.com/docs/recipes/sql-postgres-json-data-types.html
--https://www.postgresql.org/docs/9.3/static/functions-json.html
--https://stackoverflow.com/questions/26877241/query-combinations-with-nested-array-of-records-in-json-datatype/26880705#26880705
--https://blog.csdn.net/luojinbai/article/details/45091839
DROP TABLE IF EXISTS reports;
CREATE TABLE reports (rep_id int primary key, data json);
TRUNCATE TABLE reports;
INSERT INTO reports (rep_id, data)
VALUES
(1, '{"objects":[{"album": 1, "src":"fooA.png", "pos": "top"}, {"album": 2, "src":"barB.png", "pos": "top"}], "background":"background.png"}')
, (2, '{"objects":[{"album": 1, "src":"fooA.png", "pos": "top"}, {"album": 2, "src":"barC.png", "pos": "top"}], "background":"bacakground.png"}')
, (3, '{"objects":[{"album": 1, "src":"fooA.png", "pos": "middle"},{"album": 2, "src":"barB.png", "pos": "middle"}],"background":"background.png"}')
, (4, '{"objects":[{"album": 1, "src":"fooA.png", "pos": "top"}, {"album": 3, "src":"barB.png", "pos": "top"}], "background":"backgroundA.png"}')
;
/*1. example 1 */
/*
SELECT array_agg(r.rep_id) AS ids, count(*) AS ct
FROM reports r
, json_array_elements(r.data->'objects') o
where o->>'pos' in ('top','fooC.png')
GROUP BY r.data->>'background'
, o->>'album'
, o->>'scr'
ORDER BY count(*) DESC
LIMIT 3;
*/
/* 2. example 2 is what we wanted.*/
select distinct on(rep_id)r.rep_id AS id2,r.data,r.data->'objects' objects
FROM reports r
, json_array_elements(r.data->'objects') o
where o->>'pos' in ('top','middle2222')
ORDER BY r.rep_id DESC
/* 3. format output json string */
/*
select jsonb_pretty( '{"name": "Alice", "agent": {"bot": true} }'::jsonb );
-- returns the following
{
"name": "Alice",
"agent": {
"bot": true
}
}
*/
/* 4. update
update sales set info = info || '{"country": "Canada"}';
Use the || operator to concatenate existing data with new data.
The operator will either update or insert the key to the existing document.
*/
Postgresql - jsonb_pretty & dateStyle的更多相关文章
- PostgreSQL JSON函数
https://www.postgresql.org/docs/9.6/static/functions-json.html PostgreSQL 9.6.1 Documentation Prev U ...
- 使用pgstatspack分析PostgreSQL数据库性能
pgstatspack [root@test01 soft]# wget http://pgfoundry.org/frs/download.php/3151/pgstatspack_version_ ...
- PostgreSQL Configuration – managing scary settings
When it comes to highly available database servers and configuration, a very important aspect is whe ...
- PostgreSQL中initdb做了什么
在使用数据库前,是启动数据库,启动数据库前是initdb(初始化数据库):一起来看一下initdb做了什么吧. 初始化数据库的操作为: ./initdb -D /usr/local/pgsql/dat ...
- postgresql数据库的yum安装方法
实验环境>>>>>>>>>>>>>>>>>>操作系统:CentOS release 6.3 ...
- postgresql 开启远程访问
1.如果服务器启用了防火墙,需要在防火墙上开启 5432 端口. 2.修改 PostgreSQL 配置文件 postgresql.conf.postgresql.conf,Linux 配置文件所在路径 ...
- PostgreSQL的 initdb 源代码分析之十二
继续分析 /* Now create all the text config files */ setup_config(); 将其展开: 实质就是,确定各种参数,分别写入 postgresql.co ...
- [转] PostgreSQL学习手册(函数和操作符)
一.逻辑操作符: 常用的逻辑操作符有:AND.OR和NOT.其语义与其它编程语言中的逻辑操作符完全相同. 二.比较操作符: 下面是PostgreSQL中提供的比较操作符列表: 操作符 描述 < ...
- PostgreSQL学习手册(常用数据类型)
一.数值类型: 下面是PostgreSQL所支持的数值类型的列表和简单说明: 名字 存储空间 描述 范围 smallint 2 字节 小范围整数 -32768 到 +32767 integer ...
随机推荐
- 程序员、互联网从业者必读KK三大力作之《必然》总结
- mpvue支持小程序的分包加载
目录 clone mpvue-quickstart 模板 分包体验 现有项目的分包改造 这个功能可以说是让我们这些用 mpvue 的等的很焦灼,眼看着项目的大小一天天地逼近 2M,mpvue 还不能很 ...
- Linux_CentOS-服务器搭建 <五> 补充
O:文件的编码格式 1.文件转码问题 Windows中默认的文件格式是GBK(gb2312),而Linux一般都是UTF-8. 那么先说,如何查看吧.这时候强大的vi说,I can do that.( ...
- mybatis--Mapper 常见报错总结(持续总结)
本文版权归 远方的风lyh和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作. 1.The content of elements must consist of well-f ...
- SpringCloud断路器监控面板——Hystrix Dashboard
一.简介 Hystrix Dashboard是Hystrix的一个组件,Hystrix Dashboard提供一个断路器的监控面板,可以使我们更好的监控服务和集群的状态,仅仅使用Hystrix Das ...
- leetcode — valid-parentheses
import java.util.Stack; /** * Source : https://oj.leetcode.com/problems/valid-parentheses/ * * Creat ...
- U3D MonoBehaviour
一.简介 MonoBehaviour是每个脚本派生类的基类,它定义了一个脚本文件从最初被加载到最终被销毁的一个完整过程. 这个过程通过对应的方法体现出来,在不同的方法完成不同的功能,我们把这些方法称为 ...
- Hyperledger Fabric密码模块系列之BCCSP(四)
前面说过要找时间介绍一下bccsp包下面的工厂factory,so here it is. 通过factory目前可以获得两类BCCSP实例,一个是上文说的sw,还有一个是通过pkcs11实现的. B ...
- 聊聊大麦网UWP版的首页顶部图片联动效果的实现方法
随着Windows10的发布,国内已经有越来越多的厂商上架了自家的通用应用程序客户端,比如QQ.微博.大麦等.所实话,他们设计的确实很好,很符合Windows10 的设计风格和产品理念,而对于开发者而 ...
- 本地navicate for mysql怎么修改密码?
1.以前在本地设置sql库密码,就是在本地新建数据库的时候就输入,怎么也链接不上,原来是新建数据库的时候不能输入密码,需要在内部修改. 2. 打开mysql user表 3. 打开mysql user ...