How to alter a column's data type in a PostgreSQL table?

kn3l picture kn3l · Aug 23, 2011 · Viewed 200.1k times · Source

Entering the following command into a PostgreSQL interactive terminal results in an error:

ALTER TABLE tbl_name ALTER COLUMN col_name varchar (11);

What is the correct command to alter the data type of a column?

Answer

Derek Kromm picture Derek Kromm · Aug 23, 2011

See documentation here: http://www.postgresql.org/docs/current/interactive/sql-altertable.html

ALTER TABLE tbl_name ALTER COLUMN col_name TYPE varchar (11);