I have a column with type Varchar in my Postgres database that I would like to represent integers ... and now I want to change them, unfortunately this does not work using my rail migration.
change_column :table1, :columnB, :integer
Which seems to output this SQL:
ALTER TABLE table1 ALTER COLUMN columnB TYPE integer
So I tried to do this:
execute 'ALTER TABLE table1 ALTER COLUMN columnB TYPE integer USING CAST(columnB AS INTEGER)'
but this instance does not work because some of the columns have a null value ...
any ideas?
Mistake:
PGError: ERROR: invalid input syntax for integer: "" : ALTER TABLE table1 ALTER COLUMN columnB TYPE integer USING CAST(columnB AS INTEGER)
Postgres v8.3
types ruby-on-rails postgresql migration alter-table
holden
source share