Home Explore Blog CI



postgresql

2nd chunk of `doc/src/sgml/ref/create_schema.sgml`
6180f8cbfb9ff89865eb0aa8a2b7c980908c39c8d1314fd20000000100000995
 created.  If this is omitted, the
        <replaceable class="parameter">user_name</replaceable>
        is used as the schema name.  The name cannot
        begin with <literal>pg_</literal>, as such names
        are reserved for system schemas.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><replaceable class="parameter">user_name</replaceable></term>
      <listitem>
       <para>
        The role name of the user who will own the new schema.  If omitted,
        defaults to the user executing the command.  To create a schema
        owned by another role, you must be able to
        <literal>SET ROLE</literal> to that role.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><replaceable class="parameter">schema_element</replaceable></term>
      <listitem>
       <para>
        An SQL statement defining an object to be created within the
        schema. Currently, only <command>CREATE
        TABLE</command>, <command>CREATE VIEW</command>, <command>CREATE
        INDEX</command>, <command>CREATE SEQUENCE</command>, <command>CREATE
        TRIGGER</command> and <command>GRANT</command> are accepted as clauses
        within <command>CREATE SCHEMA</command>. Other kinds of objects may
        be created in separate commands after the schema is created.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><literal>IF NOT EXISTS</literal></term>
      <listitem>
       <para>
        Do nothing (except issuing a notice) if a schema with the same name
        already exists.  <replaceable class="parameter">schema_element</replaceable>
        subcommands cannot be included when this option is used.
       </para>
      </listitem>
     </varlistentry>
    </variablelist>
 </refsect1>

 <refsect1>
  <title>Notes</title>

  <para>
   To create a schema, the invoking user must have the
   <literal>CREATE</literal> privilege for the current database.
   (Of course, superusers bypass this check.)
  </para>
 </refsect1>

 <refsect1>
  <title>Examples</title>

  <para>
   Create a schema:
<programlisting>
CREATE SCHEMA myschema;
</programlisting>
  </para>

  <para>
   Create a schema for user <literal>joe</literal>; the schema will also be
   named <literal>joe</literal>:
<programlisting>
CREATE SCHEMA AUTHORIZATION joe;
</programlisting>
  </para>

  <para>
   Create a schema named <literal>test</literal>

Title: CREATE SCHEMA Parameters, Notes, and Examples
Summary
This section details the parameters used with the CREATE SCHEMA command, including schema_name, user_name, schema_element, and IF NOT EXISTS. It also mentions the required CREATE privilege for the database and provides examples of creating schemas with different options, such as specifying a user or including schema elements like tables and views.