1CREATE SCHEMA(7)        PostgreSQL 9.2.24 Documentation       CREATE SCHEMA(7)
2
3
4

NAME

6       CREATE_SCHEMA - define a new schema
7

SYNOPSIS

9       CREATE SCHEMA schema_name [ AUTHORIZATION user_name ] [ schema_element [ ... ] ]
10       CREATE SCHEMA AUTHORIZATION user_name [ schema_element [ ... ] ]
11

DESCRIPTION

13       CREATE SCHEMA enters a new schema into the current database. The schema
14       name must be distinct from the name of any existing schema in the
15       current database.
16
17       A schema is essentially a namespace: it contains named objects (tables,
18       data types, functions, and operators) whose names can duplicate those
19       of other objects existing in other schemas. Named objects are accessed
20       either by “qualifying” their names with the schema name as a prefix, or
21       by setting a search path that includes the desired schema(s). A CREATE
22       command specifying an unqualified object name creates the object in the
23       current schema (the one at the front of the search path, which can be
24       determined with the function current_schema).
25
26       Optionally, CREATE SCHEMA can include subcommands to create objects
27       within the new schema. The subcommands are treated essentially the same
28       as separate commands issued after creating the schema, except that if
29       the AUTHORIZATION clause is used, all the created objects will be owned
30       by that user.
31

PARAMETERS

33       schema_name
34           The name of a schema to be created. If this is omitted, the
35           user_name is used as the schema name. The name cannot begin with
36           pg_, as such names are reserved for system schemas.
37
38       user_name
39           The role name of the user who will own the new schema. If omitted,
40           defaults to the user executing the command. To create a schema
41           owned by another role, you must be a direct or indirect member of
42           that role, or be a superuser.
43
44       schema_element
45           An SQL statement defining an object to be created within the
46           schema. Currently, only CREATE TABLE, CREATE VIEW, CREATE INDEX,
47           CREATE SEQUENCE, CREATE TRIGGER and GRANT are accepted as clauses
48           within CREATE SCHEMA. Other kinds of objects may be created in
49           separate commands after the schema is created.
50

NOTES

52       To create a schema, the invoking user must have the CREATE privilege
53       for the current database. (Of course, superusers bypass this check.)
54

EXAMPLES

56       Create a schema:
57
58           CREATE SCHEMA myschema;
59
60       Create a schema for user joe; the schema will also be named joe:
61
62           CREATE SCHEMA AUTHORIZATION joe;
63
64       Create a schema and create a table and view within it:
65
66           CREATE SCHEMA hollywood
67               CREATE TABLE films (title text, release date, awards text[])
68               CREATE VIEW winners AS
69                   SELECT title, release FROM films WHERE awards IS NOT NULL;
70
71       Notice that the individual subcommands do not end with semicolons.
72
73       The following is an equivalent way of accomplishing the same result:
74
75           CREATE SCHEMA hollywood;
76           CREATE TABLE hollywood.films (title text, release date, awards text[]);
77           CREATE VIEW hollywood.winners AS
78               SELECT title, release FROM hollywood.films WHERE awards IS NOT NULL;
79

COMPATIBILITY

81       The SQL standard allows a DEFAULT CHARACTER SET clause in CREATE
82       SCHEMA, as well as more subcommand types than are presently accepted by
83       PostgreSQL.
84
85       The SQL standard specifies that the subcommands in CREATE SCHEMA can
86       appear in any order. The present PostgreSQL implementation does not
87       handle all cases of forward references in subcommands; it might
88       sometimes be necessary to reorder the subcommands in order to avoid
89       forward references.
90
91       According to the SQL standard, the owner of a schema always owns all
92       objects within it.  PostgreSQL allows schemas to contain objects owned
93       by users other than the schema owner. This can happen only if the
94       schema owner grants the CREATE privilege on his schema to someone else,
95       or a superuser chooses to create objects in it.
96

SEE ALSO

98       ALTER SCHEMA (ALTER_SCHEMA(7)), DROP SCHEMA (DROP_SCHEMA(7))
99
100
101
102PostgreSQL 9.2.24                 2017-11-06                  CREATE SCHEMA(7)
Impressum