从带有时区的时间到时间戳更改列 [英] alter column from time with time zone to timestamp
本文介绍了从带有时区的时间到时间戳更改列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在将 key_request
表中的名为 end_date
的列从时区更改为<我的Postgres数据库中的code> timestamp 。我尝试使用以下代码:
I am having trouble changing a column called end_date
in a table called key_request
from time with time zone to timestamp
in my Postgres database . I have tried using the following code:
alter table key_request alter column end_date type timestamp with time zone using end_date::timestamp with time zone
我一直收到以下错误:
ERROR: cannot cast type time with time zone to timestamp with time zone
$ b $的时间戳b
关于如何调整此查询以使其正常工作的任何想法?
Any idea of how I can adjust this query to work?
推荐答案
我将通过一系列步骤来做到这一点
I woul do this in a series of steps
- 更改表,添加新列
end_date1
作为带时区的时间
- 将日期从
结束日期
(旧)复制到end_date1
- 更改表,删除旧的
end_date
列 - 更改表格,将
end_date1
设置为end_date
- Alter the table, adding a new column
end_date1
astime with time zone
- Copy the date from
end_date
(old) toend_date1
- Alter the table, droping the old
end_date
column - Alter the table,reaming
end_date1
toend_date
这篇关于从带有时区的时间到时间戳更改列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文