2016-12-03 119 views
0

日期被存储这样在另一个表作为VARCHAR处理转换VARCHAR日期(BC&AD)在SQL日期格式

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 
+0

编辑您的问题并显示预期结果。如果你想“插入”某些东西,为什么你要使用'update'? –

回答

0

你需要显式转换;尝试类似的东西:

... SET wor_workcreationdate = 
     to_date(
      (select wkdocre 
      from works 
      where wor_workcreationdate = to_date(wkdocre, 'YYYY/MM/DD')), 
      'YYYY/MM/DD' 
     ) 

用减号写一年公元前是不正确的; PostgreSQL将-1295解释为1296 BC,因为0年实际上是1 BC。您可能需要修复works表,并使用YYYY/MM/DD BC作为格式说明符。