我有一个TIMESTAMP WITHOUT TIME ZONE
类型的列,希望将默认值设置为当前UTC时间.以UTC为单位获取当前时间很容易:
postgres=# select now() at time zone 'utc';
timezone
----------------------------
2013-05-17 12:52:51.337466
(1 row)
正如使用列的当前时间戳一样:
postgres=# create temporary table test(id int, ts timestamp without time zone default current_timestamp);
CREATE TABLE
postgres=# insert into test values (1) returning ts;
ts
----------------------------
2013-05-17 14:54:33.072725
(1 row)
但这要用当地时间.试图将其强制为UTC会导致语法错误:
postgres=# create temporary table test(id int, ts timestamp without time zone default now() at time zone 'utc');
ERROR: syntax error at or near "at"
LINE 1: ...int, ts timestamp without time zone default now() at time zo...