Postgres Alter table to convert column type from char to bigint

postgresql

Solution

To convert simply by parsing the string (casting):

alter table the_table alter column the_column type bigint using the_column::bigint

In fact, you can use any expression in terms of `the_column` instead of `the_column::bigint` to customise the conversion.

Note this will rewrite the table, locking out even readers until it's done.

Problem

Possible Duplicate: how to change column datatype from character to numeric in postgresql 8.4 If I have a field of type varchar (and all the values are null or string representations of numbers) how do I use alter table to convert this column type to bigint?

Original source

Related problems