How to rename table in PostgreSQL

How to rename table in PostgreSQL

In this article, we will see how to rename table in PostgreSQL. We can rename a table by using alter command.

Syntax to rename table in PostgreSQL:

ALTER TABLE table_name RENAME TO new_table_name;

Examples:

1. Rename table in PostgreSQL from test321 to new name r2schools123.

alter table test321 rename to r2schools123;

How to rename table in PostgreSQL

2. Now, rename table from other schema.

Find the list of schema using \dn meta-command.

\dn

Syntax to rename table from other schema in PostgreSQL:

ALTER TABLE schema.old RENAME TO new or SET search_path TO schema; ALTER TABLE old RENAME TO new;

alter table sales.r2schools123 rename to r2admin;