相关疑难解决方法(0)

使用UTC中的当前时间作为PostgreSQL中的默认值

我有一个TIMESTAMP WITHOUT TIME ZONE类型的列,并希望默认为UTC当前时间.以UTC格式获取当前时间很简单:

postgres=# select now() at time zone 'utc';
          timezone          
----------------------------
 2013-05-17 12:52:51.337466
(1 row)
Run Code Online (Sandbox Code Playgroud)

与使用列的当前时间戳一样:

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)
Run Code Online (Sandbox Code Playgroud)

但那使用当地时间.尝试将其强制为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 …
Run Code Online (Sandbox Code Playgroud)

postgresql timezone timestamp

151
推荐指数
5
解决办法
12万
查看次数

postgres默认时区

我安装了PostgreSQL 9,它显示的时间比服务器时间晚1小时.

跑步PostgreSQL 9节目:Select NOW()

服务器日期显示:Tue Jul 12 12:51:40 BST 2011

落后1小时,但phppgadmin显示的时区为:TimeZone Etc/GMT0

我试过进入postgresql.conf并设置timezone = GMT然后运行重启但没有改变.

我认为它会使用服务器时区的任何想法,但显然不是吗?!

解决方案!:之前我确实设置了GMT,它落后了一个小时......之后搜索结果我需要将它设置为欧洲/伦敦.这考虑到英国夏季的+1小时,GMT没有!

postgresql

81
推荐指数
7
解决办法
16万
查看次数

标签 统计

postgresql ×2

timestamp ×1

timezone ×1