Back to PostgreSQL Notes
Topic #11

PostgreSQL ALTER COLUMN


The ALTER TABLE Statement

To change the data type, or the size of a table column we have to use the ALTER TABLE statement.

The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.

The ALTER TABLE statement is also used to add and drop various constraints on an existing table.


ALTER COLUMN

We want to change the data type of the year column of the cars table from INT to VARCHAR(4).

To modify a column, use the ALTER COLUMN statement and the TYPE keyword followed by the new data type:

Example

ALTER TABLE cars
ALTER COLUMN
year TYPE VARCHAR(4);

Result

ALTER TABLE

Note: Some data types cannot be converted if the column has value. E.g. numbers can always be converted to text, but text cannot always be converted to numbers.


Change Maximum Allowed Characters

We also want to change the maximum number of characters allowed in the color column of the cars table.

Use the same syntax as above, use the ALTER COLUMN statement and the TYPE keyword followed by the new data type:

Example

ALTER TABLE cars
ALTER COLUMN color TYPE VARCHAR(30);

Result

ALTER TABLE

Want to go beyond the notes?

Join Coding Now Tech Institute's PostgreSQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

PostgreSQL ALTER COLUMN – FAQs

Quick answers about learning PostgreSQL ALTER COLUMN in PostgreSQL.

This free note from Coding Now Tech Institute explains PostgreSQL ALTER COLUMN in PostgreSQL — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every PostgreSQL topic on Coding Now Tech Institute, including PostgreSQL ALTER COLUMN, is 100% free with no signup required.
With focused practice, most students grasp PostgreSQL ALTER COLUMN in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now