Renaming multiple columns in one statement with PostgreSQL

No.

While other actions can be combined, that’s not possible with RENAME. The manual:

All the forms of ALTER TABLE that act on a single table, except
RENAME, SET SCHEMA, ATTACH PARTITION, and DETACH PARTITION can be
combined into a list of multiple alterations to be applied together.

Since RENAME is a tiny operation on a system catalog, there is no harm in running multiple statements. Do it in a single transaction to minimize locking overhead and avoid race conditions with intermediate states (which are then invisible to all other transactions).

Other actions like ALTER COLUMN ... SET TYPE are potentially expensive because they may have to rewrite the whole table. With big tables it would be wise to do as much as possible in a single statement.

Leave a Comment

error code: 521