【发布时间】:2014-12-01 06:54:00
【问题描述】:
是否可以在不先转换为其他时间字符串格式的情况下将 Unix 纪元时间值插入 tstzrange/tsrange 类型的字段?
使用 Postgres 9.3,当为 tstzrange/tsrange 提供 to_timestamp() 值时会产生无效的输入语法错误:
=> select '["to_timestamp(1267253400.069539)",]'::tstzrange;
ERROR: invalid input syntax for type timestamp with time zone: "to_timestamp(1267253400.069539)"
LINE 1: select '["to_timestamp(1267253400.069539)",]'::tstzrange;
这有点令人困惑,因为 to_timestamp() 返回一个带时区时间戳类型的值。
这并不像这些类型的字段不允许使用函数那么简单,因为 now() 函数可以正常工作:
=> select '["now()",]'::tstzrange;
tstzrange
---------------------------------------
["06-OCT-14 15:11:05.488949 -07:00",)
(1 row)
我现在使用的解决方案是将纪元时间转换为格式化的字符串(例如,'2010-02-27T06:50:00.069539-00'),它适用于 tstzrange/tsrange。我认为这不如直接提供纪元时间有效,如果有可能,我将不胜感激。
【问题讨论】:
标签: postgresql