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:
- First, specify the name of the schema that you want to modify after the ALTER SCHEMA keywords.
- Second, specify the operation you need to perform.
- ACTION can be any valid PostgreSQL operation like RENAME, DROP etc.
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 w3wiki
to gfg
:
ALTER SCHEMA w3wiki 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:
Contact Us