简体   繁体   English

PostgreSQL:使用默认时间戳插入sql语句 - dbeaver vs php

[英]PostgreSQL: insert sql statement with default timestamp - dbeaver vs php

Given this simple table: 鉴于这个简单的表:

create table comments (
  id numeric not null,
  comment text, 
  created timestamp not null default now()
);

Using dbeaver directly on the db from my pc, and executing this statement 直接在我的电脑上使用dbeaver,并执行此语句

insert into comments (id, comment)
select 1111, 'test';

the "created" field of the new record is: 2017-02-24 16:17:21 and that's my correct time (CET). 新记录的“创建”字段是: 2017-02-24 16:17:21这是我正确的时间(CET)。

When I run the very same statement from a php script (running on a linux-based webserver connected to the db), the result is 2017-02-24 15:17:21 . 当我从php脚本运行相同的语句(在连接到db的基于linux的web服务器上运行)时,结果是2017-02-24 15:17:21 The linux server time is ok (that is, CET). linux服务器时间还可以(即CET)。

What am I missing? 我错过了什么?

As per the answer at this link , change your table definition to 根据此链接的答案,将表定义更改为

create table comments (
   id numeric not null,
   comment text, 
   created timestamp not null default (now() at time zone ('CET'))
);

which will use the current datetime using the desired time zone. 它将使用所需时区使用当前日期时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM