PostgreSQL – Rename Table
To rename a table in PostgreSQL, you can use the ALTER TABLE
statement with the RENAME TO
clause. The syntax is as shown below:
ALTER TABLE current_table_name RENAME TO new_table_name;
current_table_name
is the name of the table you would like to rename, and new_table_name
is the new name you would like to give to the table.
Example: if you would like to rename a table named employees
to staff
, you can use the following command:
ALTER TABLE employees RENAME TO staff;
Renaming a table is a quick operation that does not require any copying of data. Only the metadata is updated. Even if your table is very large, the rename operation completes almost instantly.