问题很简单:如果我已经在一个列类型时间戳没有时区的数据,如果我设置类型为时间戳与时区,postgresql做这个数据是什么?
它保持当前值在本地时间,并将时区设置为本地时间的偏移量:
原文链接:https://www.f2er.com/postgresql/193342.htmlcreate table a(t timestamp without time zone,t2 timestamp with time zone); insert into a(t) values ('2012-03-01'::timestamp); update a set t2 = t; select * from a; t | t2 ---------------------+------------------------ 2012-03-01 00:00:00 | 2012-03-01 00:00:00-08 alter table a alter column t type timestamp with time zone; select * from a; t | t2 ------------------------+------------------------ 2012-03-01 00:00:00-08 | 2012-03-01 00:00:00-08
根据Alter Table手册:
if [the USING clause is] omitted,the default conversion is the same as an assignment cast from old data type to new.
根据Date/Time types手册
Conversions between timestamp without time zone and timestamp with time zone normally assume that the timestamp without time zone value should be taken or given as timezone local time. A different time zone can be specified for the conversion using
AT TIME ZONE
.