Search code examples
postgresqlherokusqlalchemyheroku-postgres

Change Heroku Postgres database column type while retaining data


I've created a Heroku Postgres database, with one of the columns being db.Integer - storing integers. However, I realize that I should actually store floating point numbers instead - i.e., db.Float.

Can I change the type of a PostgreSQL database column - after it has been created with data?


Solution

  • Yes, you can. Use following query to do that:

    ALTER TABLE $TABLE_NAME ALTER COLUMN $COLUMN_NAME TYPE <float type, e.g. float(64)>;