CREATE SCHEMA

Function

CREATE SCHEMA creates a schema.

Named objects are accessed either by "qualifying" their names with the schema name as a prefix, or by setting a search path that includes the desired schema(s). When creating named objects, you can also use the schema name as a prefix.

Optionally, CREATE SCHEMA can include sub-commands to create objects within the new schema. The sub-commands are treated essentially the same as separate commands issued after creating the schema, If the AUTHORIZATION clause is used, all the created objects are owned by this user.

Precautions

Syntax

Parameter Description

If objects in the schema on the current search path are with the same name, specify the schemas different objects are in. You can run the SHOW SEARCH_PATH command to check the schemas on the current search path.

Examples

Create a schema named role1 for the role1 role. The owner of the films and winners tables created by the clause is role1.

CREATE SCHEMA AUTHORIZATION role1
CREATE TABLE films (title text, release date, awards text[])      
CREATE VIEW winners AS         
SELECT title, release FROM films WHERE awards IS NOT NULL;

Helpful Links

ALTER SCHEMA, DROP SCHEMA