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