【发布时间】:2017-08-20 21:50:59
【问题描述】:
我想将一列数据从文本更改为类型时间戳。我的数据中没有时区。我的数据格式是 28-03-17 17:22,包括时间和日期,但没有时区。换句话说,我所有的数据都在同一个时区。我该怎么做?
我尝试了以下多种方法,但仍然找不到正确的方法。希望你能帮助我。
当然,如果我的问题能解决,我可以建一个新表。
alter table AB
alter create_time type TIMESTAMP;
ERROR: column "create_time" cannot be cast automatically to type timestamp without time zone
HINT: You might need to specify "USING create_time::timestamp without time zone".
********** Error **********
ERROR: column "create_time" cannot be cast automatically to type timestamp without time zone
SQL state: 42804
Hint: You might need to specify "USING create_time::timestamp without time zone".
alter table AB
alter create_time type TIMESTAMP without time zone;
ERROR: column "create_time" cannot be cast automatically to type timestamp without time zone
HINT: You might need to specify "USING create_time::timestamp without time zone".
********** Error **********
ERROR: column "create_time" cannot be cast automatically to type timestamp without time zone
SQL state: 42804
Hint: You might need to specify "USING create_time::timestamp without time zone".
alter table AB
alter create_time::without time zone type TIMESTAMP;
ERROR: syntax error at or near "::"
LINE 2: alter create_time::without time zone type TIMESTAM
^
********** Error **********
ERROR: syntax error at or near "::"
SQL state: 42601
Character: 50
alter table AB
alter create_time UTC type TIMESTAMP;
ERROR: syntax error at or near "UTC"
LINE 2: alter create_time UTC type TIMESTAMP;
^
********** Error **********
ERROR: syntax error at or near "UTC"
SQL state: 42601
Character: 50
【问题讨论】:
-
作为一般规则,请在您的问题中包含任何相关的错误消息。如果没有错误,请说明您认为它没有按预期工作的为什么。说它“不是正确的方法”不是很有帮助或细节。
-
添加了所有错误。请检查一下。谢谢。
-
阅读错误信息和您的代码:
USING create_time::timestamp without time zone与您的代码:create_time::without time zone type TIMESTAMP;
标签: sql postgresql timestamp