make_timestamptz()

一个用于从各个值创建 timestamptz 的函数

make_timestamptz() 是一个系统函数,用于从提供的年、月、日、小时、分钟、秒以及可选的时区组装一个 timestamptz 值。

make_timestamptz()PostgreSQL 9.4 中被添加。

用法

make_timestamptz ( year int, month int, day int, hour int, min int, sec double precision [, timezone text ] ) 
        → timestamp with time zone

所有参数都必须提供。

如果提供的任何参数无效,则会引发错误。

变更历史

示例

make_timestamptz() 的基本用法示例

postgres=# SELECT make_timestamptz(2021,8,29,23,10,56.32);
     make_timestamptz
---------------------------
 2021-08-29 23:10:56.32+01
(1 row)

提供一个明确的时区

postgres=# SELECT make_timestamptz(2020,12,1,4,55,56.32, 'JST');
     make_timestamptz
---------------------------
 2020-11-30 20:55:56.32+01
(1 row)

提供一个或多个无效的日期参数

postgres=# SELECT make_timestamptz(2021,13,29,23,10,11.22);
ERROR:  date field value out of range: 2021-13-29

提供一个或多个无效的时间参数

postgres=# SELECT make_timestamptz(2021,8,29,25,10,99.32);
ERROR:  time field value out of range: 25:10:99.32

提供一个无效的时区参数

postgres=# SELECT make_timestamptz(2001,2,12,14,13,22.36, 'Moon/Clavius');
ERROR:  time zone "Moon/Clavius" not recognized

分类

日期和时间, 系统函数

反馈

提交有关“make_timestamptz()”的任何评论、建议或更正,请点击 这里