【发布时间】:2012-11-06 14:08:37
【问题描述】:
我的数据集包含单独的年、月、日、小时、分钟和第二列,如下所示,用空格分隔:
+-------------------+
|2007|09|28|21|14|06|
|2007|09|28|21|14|06|
|2007|09|28|21|14|06|
|2007|09|28|21|14|06|
|2007|09|28|21|14|06|
+-------------------+
我想将它们集成为时间戳数据类型下的单个列。 我在时间戳数据类型中创建了一个新列,并通过以下代码更新该列:
Update s2
set dt = year || '-' || month || '-' || day
|| ' ' || hour || ':' || min || ':' || second
但我遇到了以下错误:
ERROR: column "dt" is of type timestamp without time zone but expression is of type text
LINE 1: Update temp set dt= year || '-' || month || '-' || day ||...
^
HINT: You will need to rewrite or cast the expression.
********** Error **********
ERROR: column "dt" is of type timestamp without time zone but expression is of type text
SQL state: 42804
Hint: You will need to rewrite or cast the expression.
Character: 22
此外,我可以通过varchar data-type 进行集成。
【问题讨论】:
-
column "dt" is of type timestamp without time zone but expression is of type text, You will need to rewrite or cast the expression.这似乎是个好建议。你试过了吗? -
@Mat,是的,我已经尝试过了,并将年、月、日定义为日期数据类型,将小时、分钟和秒定义为时间数据类型,然后我执行了命令,但上述错误是观察到。
标签: postgresql types timestamp