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的更多相关文章

  1. PostgreSQL JSON函数

    https://www.postgresql.org/docs/9.6/static/functions-json.html PostgreSQL 9.6.1 Documentation Prev U ...

  2. 使用pgstatspack分析PostgreSQL数据库性能

    pgstatspack [root@test01 soft]# wget http://pgfoundry.org/frs/download.php/3151/pgstatspack_version_ ...

  3. PostgreSQL Configuration – managing scary settings

    When it comes to highly available database servers and configuration, a very important aspect is whe ...

  4. PostgreSQL中initdb做了什么

    在使用数据库前,是启动数据库,启动数据库前是initdb(初始化数据库):一起来看一下initdb做了什么吧. 初始化数据库的操作为: ./initdb -D /usr/local/pgsql/dat ...

  5. postgresql数据库的yum安装方法

    实验环境>>>>>>>>>>>>>>>>>>操作系统:CentOS release 6.3 ...

  6. postgresql 开启远程访问

    1.如果服务器启用了防火墙,需要在防火墙上开启 5432 端口. 2.修改 PostgreSQL 配置文件 postgresql.conf.postgresql.conf,Linux 配置文件所在路径 ...

  7. PostgreSQL的 initdb 源代码分析之十二

    继续分析 /* Now create all the text config files */ setup_config(); 将其展开: 实质就是,确定各种参数,分别写入 postgresql.co ...

  8. [转] PostgreSQL学习手册(函数和操作符)

    一.逻辑操作符: 常用的逻辑操作符有:AND.OR和NOT.其语义与其它编程语言中的逻辑操作符完全相同. 二.比较操作符: 下面是PostgreSQL中提供的比较操作符列表: 操作符 描述 < ...

  9. PostgreSQL学习手册(常用数据类型)

    一.数值类型:     下面是PostgreSQL所支持的数值类型的列表和简单说明: 名字 存储空间 描述 范围 smallint 2 字节 小范围整数 -32768 到 +32767 integer ...

随机推荐

  1. php扩展编译方法

    linux下php已经编译,如何再为php增加新的扩展通过php自带的phpize,如我的phpize在/usr/local/php/bin/phpize1.到软件的官方或pecl.php.net去下 ...

  2. 【ASP.NET MVC系列】浅谈Google Chrome浏览器(操作篇)(下)

    ASP.NET MVC系列文章 [01]浅谈Google Chrome浏览器(理论篇) [02]浅谈Google Chrome浏览器(操作篇)(上) [03]浅谈Google Chrome浏览器(操作 ...

  3. SpringMVC入门学习(二)

    SpringMVC入门学习(二) ssm框架 springMVC  在上一篇博客中,我简单介绍了一下SpringMVC的环境配置,和简单的使用,今天我们将进一步的学习下Springmvc的操作. mo ...

  4. 快速排序的Java和python实现,亲测实际可用

    1.基本思想 快速排序每趟排序确定一个元素x的位置,使用的方式是 将大于元素x的值放大x的右边,小于元素x的值放大x的左边.当确定x的位置之后,再分别对x左边的数组和右边的数组进行快速排序即可. 2. ...

  5. About me & 一些置顶的博文

    About me 一只历史上最弱的 \(\text{hnoier}\) ... 身在 \(\text{hn}\) 弱校,除了在四大名校夹缝中生存,还要受到同校 \(\text{Julao}\) 的鄙视 ...

  6. Mybatis之分页插件pagehelper的简单使用

    最近从家里回来之后一直在想着减肥的事情,一个月都没更新博客了,今天下午没睡午觉就想着把mybatis的分页插件了解一下,由于上个月重新恢复了系统,之前创建的项目都没了,又重新创建了一个项目. 一.创建 ...

  7. [转]git提交代码时遇到代码库有更新以及本地有更新的解决方法

    本文转自:https://blog.csdn.net/myphp2012/article/details/80519156 在多人协作开发时,经常碰到同事把最新修改推送到远程库,你在本地也做了修改,这 ...

  8. MVC 【ASPX视图引擎】

    新建项目----ASP.NET MVC 4 Web 应用程序------选择模板(空).视图引擎(ASPX) 1.认识控制器Controller using System; using System. ...

  9. 【Spring】23、ApplicationContext ,ApplicationContextAware,Listener,Event 的关系解读

    tomcat容器启动流程 启动tomcat容器,加载web.xml,建立整个容器(Servlet容器,这里是tomcat吧)的上下文,ServletContext,这时web.xml有个监听器,就是C ...

  10. Hybris IMPEX.

    1.Impex是基于java Model的一种面向对象的数据操作手段,因此写impex代码前需要理清java Model之间的依赖关系.   2.基本语法:mode type[modifier=val ...