2016-12-03 82 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作爲格式說明符。