PostgreSQL: CREATE SCHEMA

From wikieduonline
Jump to navigation Jump to search
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_ROLE
  | CURRENT_USER
  | SESSION_USER

Examples[edit]

Examples Create a schema:

CREATE SCHEMA myschema;
CREATE SCHEMA IF NOT EXISTS test AUTHORIZATION joe;
CREATE SCHEMA IF NOT EXISTS datadog;
CREATE SCHEMA AUTHORIZATION joe;
CREATE SCHEMA prometheus AUTHORIZATION prometheus;
CREATE SCHEMA hollywood
    CREATE TABLE films (title text, release date, awards text[])
    CREATE VIEW winners AS
        SELECT title, release FROM films WHERE awards IS NOT NULL;

Notice that the individual subcommands do not end with semicolons.

Related[edit]

See also[edit]

Advertising: