Skip to content

Commit d9375ad

Browse files
committed
Add a reference page for CREATE SCHEMA.
1 parent be004a0 commit d9375ad

File tree

3 files changed

+244
-2
lines changed

3 files changed

+244
-2
lines changed

doc/src/sgml/ref/allfiles.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/allfiles.sgml,v 1.38 2002/04/24 02:49:50 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/allfiles.sgml,v 1.39 2002/04/25 21:47:07 tgl Exp $
33
PostgreSQL documentation
44
Complete list of usable sgml source files in this directory.
55
-->
@@ -60,6 +60,7 @@ Complete list of usable sgml source files in this directory.
6060
<!entity createLanguage system "create_language.sgml">
6161
<!entity createOperator system "create_operator.sgml">
6262
<!entity createRule system "create_rule.sgml">
63+
<!entity createSchema system "create_schema.sgml">
6364
<!entity createSequence system "create_sequence.sgml">
6465
<!entity createTable system "create_table.sgml">
6566
<!entity createTableAs system "create_table_as.sgml">

doc/src/sgml/ref/create_schema.sgml

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
<!--
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_schema.sgml,v 1.1 2002/04/25 21:47:07 tgl Exp $
3+
PostgreSQL documentation
4+
-->
5+
6+
<refentry id="SQL-CREATESCHEMA">
7+
<refmeta>
8+
<refentrytitle id="sql-createschema-title">CREATE SCHEMA</refentrytitle>
9+
<refmiscinfo>SQL - Language Statements</refmiscinfo>
10+
</refmeta>
11+
<refnamediv>
12+
<refname>
13+
CREATE SCHEMA
14+
</refname>
15+
<refpurpose>
16+
define a new schema
17+
</refpurpose>
18+
</refnamediv>
19+
<refsynopsisdiv>
20+
<synopsis>
21+
CREATE SCHEMA <replaceable class="parameter">schemaname</replaceable> [ AUTHORIZATION <replaceable class="parameter">username</replaceable> ] [ <replaceable class="parameter">schema_element</replaceable> [ ... ] ]
22+
CREATE SCHEMA AUTHORIZATION <replaceable class="parameter">username</replaceable> [ <replaceable class="parameter">schema_element</replaceable> [ ... ] ]
23+
</synopsis>
24+
25+
<refsect2 id="R2-SQL-CREATESCHEMA-1">
26+
<title>
27+
Inputs
28+
</title>
29+
<para>
30+
31+
<variablelist>
32+
<varlistentry>
33+
<term><replaceable class="parameter">schemaname</replaceable></term>
34+
<listitem>
35+
<para>
36+
The name of a schema to be created. If this is omitted, the username
37+
is used as the schema name.
38+
</para>
39+
</listitem>
40+
</varlistentry>
41+
42+
<varlistentry>
43+
<term><replaceable class="parameter">username</replaceable></term>
44+
<listitem>
45+
<para>
46+
The name of the user who will own the schema. If omitted,
47+
defaults to the user executing the command. Only superusers
48+
may create schemas owned by users other than themselves.
49+
</para>
50+
</listitem>
51+
</varlistentry>
52+
53+
<varlistentry>
54+
<term><replaceable class="parameter">schema_element</replaceable></term>
55+
<listitem>
56+
<para>
57+
An SQL statement defining an object to be created within the schema.
58+
Currently, only <command>CREATE TABLE</>, <command>CREATE VIEW</>,
59+
and <command>GRANT</> are accepted as clauses within
60+
<command>CREATE SCHEMA</>. Other kinds of objects may be created
61+
in separate commands after the schema is created.
62+
</para>
63+
</listitem>
64+
</varlistentry>
65+
</variablelist>
66+
</para>
67+
</refsect2>
68+
69+
<refsect2 id="R2-SQL-CREATESCHEMA-2">
70+
<title>
71+
Outputs
72+
</title>
73+
<para>
74+
75+
<variablelist>
76+
<varlistentry>
77+
<term><computeroutput>
78+
CREATE
79+
</computeroutput></term>
80+
<listitem>
81+
<para>
82+
Message returned if the command is successful.
83+
</para>
84+
</listitem>
85+
</varlistentry>
86+
<varlistentry>
87+
<term><computeroutput>
88+
ERROR: namespace "<replaceable class="parameter">schemaname</replaceable>" already exists
89+
</computeroutput></term>
90+
<listitem>
91+
<para>
92+
If the schema specified already exists.
93+
</para>
94+
</listitem>
95+
</varlistentry>
96+
</variablelist>
97+
</para>
98+
</refsect2>
99+
</refsynopsisdiv>
100+
101+
<refsect1 id="R1-SQL-CREATESCHEMA-1">
102+
<title>
103+
Description
104+
</title>
105+
<para>
106+
<command>CREATE SCHEMA</command> will enter a new schema
107+
into the current database.
108+
The schema name must be distinct from the name of any existing schema
109+
in the current database.
110+
</para>
111+
112+
<para>
113+
A schema is essentially a namespace:
114+
it contains named objects (tables, datatypes, functions, and operators)
115+
whose names may duplicate those of other objects existing in other
116+
schemas. Named objects are accessed either by <quote>qualifying</>
117+
their names with the schema name as a prefix, or by setting a search
118+
path that includes the desired schema(s).
119+
</para>
120+
121+
<para>
122+
Optionally, <command>CREATE SCHEMA</command> can include subcommands
123+
to create objects within the new schema. The subcommands are treated
124+
essentially the same as separate commands issued after creating the
125+
schema, except that if the <literal>AUTHORIZATION</> clause is used,
126+
all the created objects will be owned by that user.
127+
</para>
128+
129+
<refsect2 id="R2-SQL-CREATESCHEMA-3">
130+
<title>
131+
Notes
132+
</title>
133+
134+
<para>
135+
To create a schema, the invoking user must have <literal>CREATE</>
136+
privilege for the current database. (Of course, superusers bypass
137+
this check.)
138+
</para>
139+
140+
<para>
141+
Use <command>DROP SCHEMA</command> to remove a schema.
142+
</para>
143+
</refsect2>
144+
</refsect1>
145+
146+
<refsect1 id="R1-SQL-CREATESCHEMA-2">
147+
<title>
148+
Examples
149+
</title>
150+
<para>
151+
Create a schema:
152+
153+
<programlisting>
154+
CREATE SCHEMA myschema;
155+
</programlisting>
156+
</para>
157+
158+
<para>
159+
Create a schema for user <literal>joe</> --- the schema will also
160+
be named <literal>joe</>:
161+
162+
<programlisting>
163+
CREATE SCHEMA AUTHORIZATION joe;
164+
</programlisting>
165+
</para>
166+
167+
<para>
168+
Create a schema and create a table and view within it:
169+
170+
<programlisting>
171+
CREATE SCHEMA hollywood
172+
CREATE TABLE films (title text, release date, awards text[])
173+
CREATE VIEW winners AS
174+
SELECT title, release FROM films WHERE awards IS NOT NULL;
175+
</programlisting>
176+
Notice that the individual subcommands do not end with semicolons.
177+
</para>
178+
179+
<para>
180+
The following is an equivalent way of accomplishing the same result:
181+
<programlisting>
182+
CREATE SCHEMA hollywood;
183+
CREATE TABLE hollywood.films (title text, release date, awards text[]);
184+
CREATE VIEW hollywood.winners AS
185+
SELECT title, release FROM hollywood.films WHERE awards IS NOT NULL;
186+
</programlisting>
187+
</para>
188+
</refsect1>
189+
190+
<refsect1 id="R1-SQL-CREATESCHEMA-3">
191+
<title>
192+
Compatibility
193+
</title>
194+
195+
<refsect2 id="R2-SQL-CREATESCHEMA-4">
196+
<title>
197+
SQL92
198+
</title>
199+
200+
<para>
201+
SQL92 allows a <literal>DEFAULT CHARACTER SET</> clause in
202+
<command>CREATE SCHEMA</command>, as well as more subcommand types
203+
than are presently accepted by <productname>PostgreSQL</productname>.
204+
</para>
205+
206+
<para>
207+
SQL92 specifies that the subcommands in <command>CREATE SCHEMA</command>
208+
may appear in any order. The present
209+
<productname>PostgreSQL</productname> implementation does not handle all
210+
cases of forward references in subcommands; it may sometimes be necessary
211+
to reorder the subcommands to avoid forward references.
212+
</para>
213+
214+
<para>
215+
In SQL92, the owner of a schema always owns all objects within it.
216+
<productname>PostgreSQL</productname> allows schemas to contain objects
217+
owned by users other than the schema owner. This can happen only if the
218+
schema owner grants <literal>CREATE</> rights on his schema to someone
219+
else.
220+
</para>
221+
</refsect2>
222+
</refsect1>
223+
</refentry>
224+
225+
<!-- Keep this comment at the end of the file
226+
Local variables:
227+
mode: sgml
228+
sgml-omittag:nil
229+
sgml-shorttag:t
230+
sgml-minimize-attributes:nil
231+
sgml-always-quote-attributes:t
232+
sgml-indent-step:1
233+
sgml-indent-data:t
234+
sgml-parent-document:nil
235+
sgml-default-dtd-file:"../reference.ced"
236+
sgml-exposed-tags:nil
237+
sgml-local-catalogs:"/usr/lib/sgml/catalog"
238+
sgml-local-ecat-files:nil
239+
End:
240+
-->

doc/src/sgml/reference.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!-- reference.sgml
2-
$Header: /cvsroot/pgsql/doc/src/sgml/reference.sgml,v 1.27 2002/04/24 02:49:50 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/reference.sgml,v 1.28 2002/04/25 21:47:06 tgl Exp $
33

44
PostgreSQL Reference Manual
55
-->
@@ -69,6 +69,7 @@ PostgreSQL Reference Manual
6969
&createLanguage;
7070
&createOperator;
7171
&createRule;
72+
&createSchema;
7273
&createSequence;
7374
&createTable;
7475
&createTableAs;

0 commit comments

Comments
 (0)