DataReportive dashboard interface showing database report generation

How to Rename a Table in PostgreSQL

Renaming a table in PostgreSQL is a simple process that can be done using the ALTER TABLE statement. In this tutorial, we will walk you through the steps to rename a table in your PostgreSQL database.

Step-by-Step Guide

To rename a table in PostgreSQL, use the following SQL syntax:

ALTER TABLE current_table_name RENAME TO new_table_name;

Where current_table_name is the existing name of the table, and new_table_name is the desired new name for the table.

Example

Suppose you have a table called employees and you want to rename it to staff. You can run the following SQL command:

ALTER TABLE employees RENAME TO staff;

After executing this command, the table employees will be renamed to staff.

Considerations

  • The new table name must not already exist in the database.
  • You need sufficient privileges to alter the table.
  • Renaming a table does not affect any data within the table or its structure.

Automate PostgreSQL reporting with DataReportive

Turn your PostgreSQL queries into scheduled reports delivered to your team or customers.

Conclusion

Renaming a table in PostgreSQL is a straightforward process using the ALTER TABLE command. It’s a simple, yet powerful way to manage your database schema as your needs evolve.

For more PostgreSQL tutorials, check out our other articles!