How to convert a table column to another data type

Posted by holden on Stack Overflow See other posts from Stack Overflow or by holden
Published on 2010-05-21T11:50:17Z Indexed on 2010/05/21 12:10 UTC
Read the original article Hit count: 249

I have a column with the type of Varchar in my Postgres database which I meant to be integers... and now I want to change them, unfortunately this doesn't seem to work using my rails migration.

change_column :table1, :columnB, :integer

So I tried doing this:

execute 'ALTER TABLE "table1" ALTER COLUMN "columnB" TYPE integer USING CAST(columnB AS INTEGER)'

but cast doesn't work in this instance because some of the column are null...

any ideas?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about postgresql