title: "ALTER ... SWAP"
description: "ALTER ... SWAP
atomically renames two items."
menu:
main:
parent: 'commands'
ALTER ... SWAP
atomically renames two items.
{{< diagram "alter-swap.svg" >}}
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. |
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;
The privileges required to execute this statement are:
{{< include-md file="shared-content/sql-command-privileges/alter-swap.md" >}}