Change the column data type in Postgresql

In this Tutorial we will see how to change the column data type in Postgresql with example. Lets see

  • How to change the data type of single column in postgresql
  • How to change the data type of Multiple column in Postgresql

With an example for each.

Syntax:

ALTER TABLE table_name
ALTER COLUMN column_name TYPE new_data_type;

The table that we use is

odetails:

Change column datatype in postgresql 1

 

Change the data type of single column in postgresql :

Lets change data type of ono column to VARCHAR

ALTER TABLE odetails
ALTER COLUMN ono TYPE VARCHAR;

So the result is

Change column datatype in postgresql 2

 

Change the data type of multiple columns in postgresql :

Let’s change data type of ono column and bno column to TEXT and VARCHAR


ALTER TABLE odetails
ALTER COLUMN ono TYPE TEXT,
ALTER COLUMN bno TYPE VARCHAR;

Separate each ALTER COLUMN clause by a comma (,) in order to change the data type of multiple columns in postgresql.

So the Result is :

Change column datatype in postgresql 3