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