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. CountDownLatch 和 CyclicBarrier 的基本使用

    CountDownLatch 和 CyclicBarrier 是并发编程中常用的辅助类,两者使用上有点类似,但又有不同. 一.CountDownLatch CountDownLatch 可是实现类似计 ...

  2. ProxySQL 配置详解及读写分离(+GTID)等功能说明 (完整篇)

    ProxySQL是灵活强大的MySQL代理层, 是一个能实实在在用在生产环境的MySQL中间件,可以实现读写分离,支持 Query 路由功能,支持动态指定某个 SQL 进行 cache,支持动态加载配 ...

  3. Spring之Bean的配置方式

    在博客中为了演示容器Bean实例化时暴露出的几个接口,将UserBean配置在XML中,其实常见的Bean的配置有3种.1.基于xml配置Bean 2.使用注解定义Bean 3.基于java类提供Be ...

  4. RIP笔记

    RIP(工作中没见人用过这种古老的协议,了解一下距离矢量的思想即可) RIPv2支持VLSM但不支持CIDR RIP工作在应用层,用UDP封装,端口是520 无论是RIPv1还是RIPv2都既支持周期 ...

  5. [转]docker-compose教程(安装,使用, 快速入门)

    本文转自:https://blog.csdn.net/pushiqiang/article/details/78682323 教程基于ubuntu下最新的compose版本3 参考: https:// ...

  6. Oracle入门《Oracle介绍》第一章1-4 Oracle 用户管理

    1.Oracle 默认用户 只有用合法的用户帐号才能访问Oracle数据库 Oracle 有几个默认的数据库用户 数据库中所有数据字典表和视图都存储在 SYS 模式中.SYS用户主要用来维护系统信息和 ...

  7. NPOI 通过excel模板写入数据并导出

    private void ToExcel(string id) { //模板文件 string TempletFileName = Server.MapPath("template.xls& ...

  8. C# MVC 用户登录状态判断

    来源:https://www.cnblogs.com/cherryzhou/p/4978342.html 在Filters文件夹下添加一个类AuthenticationAttribute ,代码如下: ...

  9. Mysql锁原理浅谈

    锁类型/引擎 行锁 表锁 页锁 MyISAM 有 InnoDB 有 有 BDB(被InnoDB取代) 有 有 锁的分类 表锁:开销小,加锁快,不会死锁,粒度大,冲突率高,并发低. 行锁:开销大,加锁慢 ...

  10. 移动端meta整理

    <!doctype html> <html> <head> <meta charset="utf-8"> <meta http ...