--year 2000 was a leap year so February had 29 days
select '2000-02-29'::timestamp;
-- timestamp
-----------------------
-- 2000-02-29 00:00:00
--year 2001 was not a leap year so February had 28 days
select '2001-02-29'::timestamp;
--ERROR: date/time field value out of range: "2001-02-29"
--LINE 1: select '2001-02-29'::timestamp;
-- ^
select '2000-99-00'::timestamp;
--ERROR: date/time field value out of range: "2000-99-00"
--LINE 1: select '2000-99-00'::timestamp;
-- ^
--HINT: Perhaps you need a different "datestyle" setting.
1条答案
按热度按时间qvtsj1bj1#
2000-99-00
在PostgreSQL中不是有效的时间戳,在任何标准的地面系统中也不是。您建议的最大值/最小值过于简单化-系统根据公元前4713年到公元294276年之间的实际月份长度和闰年验证输入。如果是非标准格式,可以在
to_timestamp()
中设置掩码,也可以在datestyle
设置中设置默认输入输出格式。对于大多数常用的RDBMS,如果您只想运行一个快速测试,而不必设置自己的集群,您可以使用在线工具:dbfiddle.uk,db-fiddle.com,sqlfiddle.com