PostgreSQL 13: 日期格式新增对FF1-FF6的支持

2016 SQL标准定义了FF1-FF6时间格式,PostgreSQL 13 版本的日期格式中新增了对FF1-FF6格式的支持,手册说明如下。

手册说明

Add format specifications FF1-FF6 to control display of 1-6 subsecond digits (Alexander Korotkov, Nikita Glukhov, Teodor Sigaev, Oleg Bartunov)
These patterns can be used by to_char(), to_timestamp(), and jsonpath s .datetime().

先来看看手册中关于FF1-FF6的解说。

关于FF1-FF6

FF1-FF6表示时间数据类型秒后的第一位到第六位,手册说明如下:

  • FF1: 秒的1/10
  • FF2: 秒的1/100
  • FF3: 秒的1/1000,毫秒
  • FF4: 毫秒的1/10
  • FF5: 毫秒的1/100
  • FF6: 毫秒的1/1000,微妙

下面通过示例说明。

举例说明

PostgreSQL 13 执行以下SQL,如下:

1
2
3
4
5
6
7
8
9
10
11
12
postgres=# SELECT now(),
to_char(now(),'HH24:MI:SS.FF1'),
to_char(now(),'HH24:MI:SS.FF2'),
to_char(now(),'HH24:MI:SS.FF3'),
to_char(now(),'HH24:MI:SS.FF4'),
to_char(now(),'HH24:MI:SS.FF5'),
to_char(now(),'HH24:MI:SS.FF6')
;
now | to_char | to_char | to_char | to_char | to_char | to_char
-------------------------------+------------+-------------+--------------+---------------+----------------+-----------------
2020-07-18 20:58:08.646871+08 | 20:58:08.6 | 20:58:08.64 | 20:58:08.646 | 20:58:08.6468 | 20:58:08.64687 | 20:58:08.646871
(1 row)

从以上看出FF1-FF6分别返回了秒后的第一位到第六位。

参考

最后推荐和张文升共同编写的《PostgreSQL实战》,本书基于PostgreSQL 10 编写,共18章,重点介绍SQL高级特性、并行查询、分区表、物理复制、逻辑复制、备份恢复、高可用、性能优化、PostGIS等,涵盖大量实战用例!

购买链接:https://item.jd.com/12405774.html

PostgreSQL实战
感谢支持!
0%