我有一个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...