Skip to content
Related Articles
Open in App
Not now

Related Articles

PostgreSQL – Rename Table

Improve Article
Save Article
  • Last Updated : 28 Aug, 2020
Improve Article
Save Article

PostgreSQL has a RENAME clause that is used with the ALTER TABLE statement to rename the name of an existing table.

ALTER TABLE table_name
RENAME TO new_table_name; 

In the above syntax:

  • First, specify the name of the table which you want to rename after the ALTER TABLE clause.
  • Second, give the new table name after the RENAME TO clause.

Attempting to rename a table that doesn’t exist leads to PostgreSQL raising an error. To rename multiple tables, one has to execute multiple ALTER TABLE RENAME TO statements. It’s not possible to do it in a single statement.
For the purpose of example let’s first create a table using the below statements and then we will attempt to rename it:

CREATE TABLE vendors (
    id serial PRIMARY KEY,

Now check if the table has been successfully created using the below statement:

SELECT * FROM vendors;

Now that our table is ready, let’s jump into an example.

In this we will rename the vendors table to suppliers, using the following ALTER TABLE RENAME TO statement:

ALTER TABLE vendors RENAME TO suppliers;

Now we can verify if the name has been changed using the below statement:

SELECT * FROM suppliers;


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!