[英]Convert varchar dates (BC & AD) to date format in sql
这样将日期以varchars的形式存储在另一个表中
select wkdocre from works;
wkdocre
-------------
+1654/12/31
+1706/12/31
+1667/12/31
-0332/12/31
-0332/12/31
-1295/12/31
我想将这些日期插入具有这样的日期类型的属性的另一个表中
update ns_works set wor_workcreationdate=(select wkdocre from works where wor_workcreationdate=wkdocre);
我得到这个错误
ERROR: operator does not exist: ns_workcreationdate = dateofcreation
LINE 1: ...lect wkdocre from works where wor_workcreationdate=wkdocre);
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
谢谢
所需结果
select wor_creationdate from ns_works;
wor_creationdate
-------------
1654/12/31
1706/12/31
1667/12/31
-0332/12/31
-0332/12/31
-1295/12/31
您需要显式转换; 尝试这样的事情:
... SET wor_workcreationdate =
to_date(
(select wkdocre
from works
where wor_workcreationdate = to_date(wkdocre, 'YYYY/MM/DD')),
'YYYY/MM/DD'
)
但是用负号写BC年是不正确的。 PostgreSQL将-1295
解释为1296 BC
,因为0年实际上是1 BC。 您可能需要修复works
表,并使用YYYY/MM/DD BC
作为格式说明符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.