我有一个TIMESTAMP WITHOUT TIME ZONE类型的列,并希望默认为UTC的当前时间。获取当前时间在UTC是很容易:
原文链接:https://www.f2er.com/postgresql/193795.htmlpostgres=# 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...