PostgreSQL alter type timestamp without time zone – > with time zone

PostgreSQL alter type timestamp without time zone – > with time zone,第1张

概述问题很简单:如果我已经在一个列类型时间戳没有时区的数据,如果我设置类型为时间戳与时区,postgresql做这个数据是什么? 它保持当前值在本地时间,并将时区设置为本地时间的偏移量: create table a(t timestamp without time zone, t2 timestamp with time zone);insert into a(t) values ('2012-0 问题很简单:如果我已经在一个列类型时间戳没有时区的数据,如果我设置类型为时间戳与时区,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-08alter 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.

总结

以上是内存溢出为你收集整理的PostgreSQL alter type timestamp without time zone – > with time zone全部内容,希望文章能够帮你解决PostgreSQL alter type timestamp without time zone – > with time zone所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/sjk/1171726.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-02
下一篇2022-06-02

发表评论

登录后才能评论

评论列表(0条)

    保存