Open In App

PostgreSQL – ALTER SCHEMA

PostgreSQL has A ALTER SCHEMA statement that is used to modify the definition of an existing schema.

Syntax:
ALTER SCHEMA schema_name
ACTION xyz;

Let’s analyze the above syntax:



Let’s take some examples of using the ALTER SCHEMA statement to get a better understanding.

Example 1:
This example uses the ALTER SCHEMA statement to rename the schema geeksforgeeks to gfg:



ALTER SCHEMA geeksforgeeks
RENAME TO gfg;

To verify the change use the below statement:

SELECT 
  * 
FROM 
    pg_catalog.pg_namespace
ORDER BY 
    nspname;

Output:

Example 2:
The following example uses the ALTER SCHEMA statement to change the owner of the schema gfg to from Raju to postgres:

ALTER SCHEMA gfg
OWNER TO postgres;

To verify the change use the below statement:

SELECT 
  * 
FROM 
    pg_catalog.pg_namespace
ORDER BY 
    nspname;

Output:

Article Tags :