1
我想將所有非日期格式化的字符串更改爲date nil,然後更改列類型。我曾計劃使用以下內容:Rails/POSTGRES ISDATE函數
class SetSubmitDateForAllMyTables < ActiveRecord::Migration
def self.up
MyTable.connection.execute("UPDATE my_table SET submit_date = NULL WHERE NOT ISDATE(submit_date)")
MyTable.connection.execute("UPDATE my_table SET submit_date=created_at WHERE submit_date IS NULL")
change_column :my_table, :submit_date, :date
end
def self.down
end
end
但是,ISDATE函數在POSTGRES中似乎不是有效的。我怎樣才能做到這一點?
我打開使用:
MyTable.all.each do |list|
這是一次性改變嗎?數據是什麼樣的? – 2015-01-26 21:56:22
@ MikeSherrill'CatRecall」這應該是能在那些還沒有這種遷移任何環境中運行遷移,所以希望一次性的。該字段是一個字符串,因此它可以包含任何字母數字。 – steventnorris 2015-01-26 22:01:05
當您談論日期轉換時,短語*任何字母數字*涵蓋了大量罪過。它能真的*包含'wibble','01/02/03','1963年4月4日','Jug 134,2015'等值嗎? – 2015-01-26 22:20:01