CREATE SCHEMA
Defines a new schema.
Synopsis
CREATE SCHEMA <schema_name> [AUTHORIZATION <role_specification>]
[<schema_element> [ ... ]]
CREATE SCHEMA AUTHORIZATION <role_specification> [<schema_element> [ ... ]]
CREATE SCHEMA IF NOT EXISTS <schema_name> [ AUTHORIZATION <role_specification> ]
CREATE SCHEMA IF NOT EXISTS AUTHORIZATION <role_specification>
-- where <role_specification> can be:
<user_name>
| CURRENT_USER
| SESSION_USER
Description
CREATE SCHEMA
enters a new schema into the current database. The schema name must be distinct from the name of any existing schema in the current database.
A schema is essentially a namespace: it contains named objects (tables, data types, functions, and operators) whose names may duplicate those of other objects existing in other schemas. 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). A CREATE
command specifying an unqualified object name creates the object in the current schema (the one at the front of the search path, which can be determined with the function current_schema()
).
Optionally, CREATE SCHEMA
can include subcommands to create objects within the new schema. The subcommands are treated essentially the same as separate commands issued after creating the schema, except that if the AUTHORIZATION
clause is used, all the created objects will be owned by that role.