ALTER TABLE table_name
RENAME TO new_table_name;

Does it delete the table named table_name and create a new table called new_table_name, or does it rename it right away?

1 Answers

1
Laurenz Albe On Best Solutions

No, all renaming an object in PostgreSQL does is to change a single entry in a catalog table.

In the case of tables, this is the relname column in pg_class.

All internal references to the table are done via its “object ID”.

The exception here are functions. Function bodies are strings, and if you refer to a table by name in a function, that is not updated.