1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Support CREATE SCHEMA IF NOT EXISTS.

Per discussion, schema-element subcommands are not allowed together with
this option, since it's not very obvious what should happen to the element
objects.

Fabrízio de Royes Mello
This commit is contained in:
Tom Lane
2012-10-03 19:47:11 -04:00
parent 994c36e01d
commit fb34e94d21
9 changed files with 105 additions and 0 deletions

View File

@ -23,6 +23,8 @@ PostgreSQL documentation
<synopsis>
CREATE SCHEMA <replaceable class="parameter">schema_name</replaceable> [ AUTHORIZATION <replaceable class="parameter">user_name</replaceable> ] [ <replaceable class="parameter">schema_element</replaceable> [ ... ] ]
CREATE SCHEMA AUTHORIZATION <replaceable class="parameter">user_name</replaceable> [ <replaceable class="parameter">schema_element</replaceable> [ ... ] ]
CREATE SCHEMA IF NOT EXISTS <replaceable class="parameter">schema_name</replaceable> [ AUTHORIZATION <replaceable class="parameter">user_name</replaceable> ]
CREATE SCHEMA IF NOT EXISTS AUTHORIZATION <replaceable class="parameter">user_name</replaceable>
</synopsis>
</refsynopsisdiv>
@ -98,6 +100,17 @@ CREATE SCHEMA AUTHORIZATION <replaceable class="parameter">user_name</replaceabl
</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</>
subcommands cannot be included when this option is used.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
@ -129,6 +142,15 @@ CREATE SCHEMA AUTHORIZATION joe;
</programlisting>
</para>
<para>
Create a schema named <literal>test</> that will be owned by user
<literal>joe</>, unless there already is a schema named <literal>test</>.
(It does not matter whether <literal>joe</> owns the pre-existing schema.)
<programlisting>
CREATE SCHEMA IF NOT EXISTS test AUTHORIZATION joe;
</programlisting>
</para>
<para>
Create a schema and create a table and view within it:
<programlisting>
@ -177,6 +199,11 @@ CREATE VIEW hollywood.winners AS
schema owner. This can happen only if the schema owner grants the
<literal>CREATE</> privilege on his schema to someone else.
</para>
<para>
The <literal>IF NOT EXISTS</literal> option is a
<productname>PostgreSQL</productname> extension.
</para>
</refsect1>
<refsect1>