2 Ways to Rename a Table in PostgreSQL

Last updated on February 5, 2022 A Goodman Loading... Post a comment

This short article shows you 2 different ways to rename a table in a PostgreSQL database. The first approach is to execute the ALTER TABLE statement with the RENAME keyword and the second one is to make use of the graphical user interface of pgAdmin.

Using ALTER TABLE statement

You can change the name of an existing table in Postgres as shown below:

ALTER TABLE <current name>
RENAME TO <new name>;

This example renames a table named members to users:

ALTER TABLE members 
RENAME TO users;

Via pgAdmin

If you’re new to Postgres, you’re likely to frequently make use of pgAdmin to manage your databases.

1. Log yourself into your pgAdmin.

2. From the left-hand sidebar, navigate to Servers > [your server name] > Databases > [your database] > Schemas > Public > Tables. If you get confused, see the screenshot below:

3. Right-click on the table that you want to change the name then select Properties… from the popup menu:

4. A dialog will show up. Enter the name you like into the text field labeled with Name the hit the Save button to apply your change:

Now right-click on Databases and select Refresh to see the new name.

Conclusion

You’ve learned more than one way to rename a table in PostgreSQL. If you’d like to sharpen your skills and gain more experience with PostgreSQL then take a look at the following articles:

You can also check out our database topic page for the latest tutorials and examples.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Related Articles