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
12postgres=# 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
分别返回了秒后的第一位到第六位。