2017-03-07 80 views
3

我需要轉換在PSQL中的一個表中的幾列,我真的不想放棄表來解決這個問題(這是我的最後手段)。有沒有辦法做到這一點,因爲當我寫:如何將沒有時區的時間轉換爲沒有時區的時間戳?

ALTER TABLE table ALTER TABLE column type TIMESTAMP without time zone using column::TIMESTAMP without time zone; 

它不工作,說:

ERROR:cannot cast type time without time zone to timestamp without time zone. 

附:如果可能,我想避免刪除列,因爲我已經使用這些列的索引。

+1

是否可以添加新列,更新表,並刪除舊的列? –

+0

剛剛編輯,我想避免那大聲笑 –

+0

無論如何,您將需要更改索引的100% - 所以放棄索引更改類型和創建另一個索引可能會更快 –

回答

5

如果您想要的日期部分是今天:

alter table the_table 
alter column the_column type timestamp without time zone 
using current_date + the_column 
+0

我的救生員。謝謝,它的作品=) –

相關問題