The ALTER ... SWAP command enables the exchange of names between two database objects, such as tables, materialized views, views, sources, sinks, or subscriptions. It simplifies the process of renaming two objects by allowing them to be swapped in a single operation.

The objects being swapped must be of the same type; otherwise, an error will be returned.

Syntax

ALTER [ TABLE | MATERIALIZED VIEW | VIEW | SOURCE | SINK | SUBSCRIPTION ] name
SWAP WITH target_name;

Parameter

ParameterDescription
nameThe current name of the database object to swap.
target_nameThe target name of the database object you want to swap with.

Example

ALTER MATERIALIZED VIEW historical_sales
SWAP WITH current_sales;