Rename the column name in Postgresql – change column name

In this Tutorial we will see how to change or rename the column name in Postgresql with example. Let’s see

  • How to (change) rename the column name of Single column in Postgresql
  • How to (change) rename the column name of Multiple column in Postgresql

With an example for each.

Syntax:

ALTER TABLE table_name RENAME COLUMN column_name TO new_column_name;

The table that we use is

odetails:

Change or Rename column name in postgresql 1

 

Rename or Change single column name in postgresql :

Lets rename the single column

ALTER TABLE odetails
RENAME COLUMN ono TO order_no;

So the result is

Change or Rename column name in postgresql 2

 

Rename or change the column name of multiple columns in postgresql:

We can rename only one column at a time. In order to rename multiple column we have to specify syntax multiple times.


ALTER TABLE odetails
RENAME COLUMN ono TO order_no;
ALTER TABLE odetails
RENAME COLUMN bno TO batch_no;

So we renamed both the column so the result will be

Change or Rename column name in postgresql 3

                                                                                                     

Author

  • Sridhar Venkatachalam

    With close to 10 years on Experience in data science and machine learning Have extensively worked on programming languages like R, Python (Pandas), SAS, Pyspark.