ALTER … SWAP

ALTER ... SWAP atomically renames two items.

Syntax

ALTER CLUSTER SCHEMA name SWAP WITH target_name
Field Use
name The identifier of the item you want to swap.
target_name The target identifier of the item you want to swap with.

Examples

Swapping two items is useful for a blue/green deployment

CREATE SCHEMA blue;
CREATE TABLE blue.numbers (n int);

CREATE SCHEMA green;
CREATE TABLE green.tags (tag text);

ALTER SCHEMA blue SWAP WITH green;

-- The schema which was previously named 'green' is now named 'blue'.
SELECT * FROM blue.tags;

Privileges

The privileges required to execute this statement are:

  • Ownership of both objects being swapped.

See also

Back to top ↑