加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

PostgreSQL alter type timestamp without time zone – >

发布时间:2020-12-13 16:44:05 所属栏目:百科 来源:网络整理
导读:问题很简单:如果我已经在一个列类型时间戳没有时区的数据,如果我设置类型为时间戳与时区,postgresql做这个数据是什么? 它保持当前值在本地时间,并将时区设置为本地时间的偏移量: create table a(t timestamp without time zone,t2 timestamp with time
问题很简单:如果我已经在一个列类型时间戳没有时区的数据,如果我设置类型为时间戳与时区,postgresql做这个数据是什么?
它保持当前值在本地时间,并将时区设置为本地时间的偏移量:
create 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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读