Syntax

CREATE SCHEMA [IF NOT EXISTS] [database_name.]schema_name [AUTHORIZATION user_name];

CREATE SCHEMA [ IF NOT EXISTS ] AUTHORIZATION user_name;

Parameters

Parameter or clauseDescription
schema_nameThe name of the schema to be created.
IF NOT EXISTS clauseCreates a schema if the schema name has not already been used. Otherwise throws an error.
database_nameThe name of the database for the schema to be created in. If not specified, the schema will be created in the default database dev.
AUTHORIZATION clauseSpecifies the owner or authorized user of the schema. If the schema_name is omitted, the user_name is used as the schema name.
user_nameSpecifies the username of the owner or authorized user of the schema.

Examples

CREATE SCHEMA IF NOT EXISTS schema_1;

Names and unquoted identifiers are case-insensitive. Therefore, you must double-quote any of these fields for them to be case-sensitive. See also Identifiers.

Examples of AUTHORIZATION clause

-- Create a new schema for the user 'joe'. As the schema name is omitted, the schema name is default to the user name 'joe'.
CREATE SCHEMA IF NOT EXISTS AUTHORIZATION joe;

----RESULT
CREATE_SCHEMA

-- Create a new schema named 'new_schema', and assign 'joe' as the owner.
CREATE SCHEMA IF NOT EXISTS new_schema AUTHORIZATION joe;

----RESULT
CREATE_SCHEMA

-- Display the existing schemas. You will see 'joe' and 'new_schema'.
SHOW SCHEMAS;

----RESULT
        Name
--------------------
 information_schema
 public
 pg_catalog
 joe
 new_schema
 rw_catalog
(6 rows)