make_timestamp() 是一个系统函数,用于根据提供的年、月、日、时、分和秒来组合一个 timestamp 值。
make_timestamp() 在 PostgreSQL 9.4 中被添加。
用法
make_timestamp (yearint,monthint,dayint,hourint,minint,secdouble precision) →timestamp
必须提供所有参数。
如果提供的任何参数无效,则会引发错误。
变更历史
- PostgreSQL 9.4
- 添加(提交 84df54b2)
示例
make_timestamp() 的基本用法示例
postgres=# SELECT make_timestamp(2021,8,29,23,10,56.32);
make_timestamp
------------------------
2021-08-29 23:10:56.32
(1 row)
提供一个或多个无效的日期参数
postgres=# SELECT make_timestamp(2021,13,29,23,10,11.22); ERROR: date field value out of range: 2021-13-29
提供一个或多个无效的时间参数
postgres=# SELECT make_timestamp(2021,8,29,25,10,99.32); ERROR: time field value out of range: 25:10:99.32
参考资料
- PostgreSQL 文档: 日期/时间函数
