1- <!-- $PostgreSQL: pgsql/doc/src/sgml/ddl.sgml,v 1.65 2006/10/16 17:28:03 momjian Exp $ -->
1+ <!-- $PostgreSQL: pgsql/doc/src/sgml/ddl.sgml,v 1.66 2006/10/22 03:03:40 tgl Exp $ -->
22
33<chapter id="ddl">
44 <title>Data Definition</title>
@@ -146,8 +146,10 @@ DROP TABLE products;
146146</programlisting>
147147 Attempting to drop a table that does not exist is an error.
148148 Nevertheless, it is common in SQL script files to unconditionally
149- try to drop each table before creating it, ignoring the error
150- messages.
149+ try to drop each table before creating it, ignoring any error
150+ messages, so that the script works whether or not the table exists.
151+ (If you like, you can use the <literal>DROP TABLE IF EXISTS</> variant
152+ to avoid the error messages, but this is not standard SQL.)
151153 </para>
152154
153155 <para>
@@ -174,7 +176,7 @@ DROP TABLE products;
174176
175177 <para>
176178 A column can be assigned a default value. When a new row is
177- created and no values are specified for some of the columns, the
179+ created and no values are specified for some of the columns, those
178180 columns will be filled with their respective default values. A
179181 data manipulation command can also request explicitly that a column
180182 be set to its default value, without having to know what that value is.
@@ -245,7 +247,7 @@ CREATE TABLE products (
245247 standard data type that accepts only positive numbers. Another issue is
246248 that you might want to constrain column data with respect to other
247249 columns or rows. For example, in a table containing product
248- information, there should only be one row for each product number.
250+ information, there should be only one row for each product number.
249251 </para>
250252
251253 <para>
@@ -400,11 +402,6 @@ CREATE TABLE products (
400402 ensure that a column does not contain null values, the not-null
401403 constraint described in the next section can be used.
402404 </para>
403-
404- <para>
405- Check constraints can be useful for enhancing the performance of
406- partitioned tables. For details see <xref linkend="ddl-partitioning">.
407- </para>
408405 </sect2>
409406
410407 <sect2>
@@ -461,7 +458,7 @@ CREATE TABLE products (
461458 <literal>NULL</literal> constraint. This does not mean that the
462459 column must be null, which would surely be useless. Instead, this
463460 simply selects the default behavior that the column may be null.
464- The <literal>NULL</literal> constraint is not defined in the SQL
461+ The <literal>NULL</literal> constraint is not present in the SQL
465462 standard and should not be used in portable applications. (It was
466463 only added to <productname>PostgreSQL</productname> to be
467464 compatible with some other database systems.) Some users, however,
@@ -556,7 +553,7 @@ CREATE TABLE products (
556553 In general, a unique constraint is violated when there are two or
557554 more rows in the table where the values of all of the
558555 columns included in the constraint are equal.
559- However, null values are not considered equal in this
556+ However, two null values are not considered equal in this
560557 comparison. That means even in the presence of a
561558 unique constraint it is possible to store duplicate
562559 rows that contain a null value in at least one of the constrained
@@ -626,8 +623,10 @@ CREATE TABLE example (
626623 </para>
627624
628625 <para>
629- A table can have at most one primary key (while it can have many
630- unique and not-null constraints). Relational database theory
626+ A table can have at most one primary key. (There can be any number
627+ of unique and not-null constraints, which are functionally the same
628+ thing, but only one can be identified as the primary key.)
629+ Relational database theory
631630 dictates that every table must have a primary key. This rule is
632631 not enforced by <productname>PostgreSQL</productname>, but it is
633632 usually best to follow it.
@@ -878,7 +877,7 @@ CREATE TABLE order_items (
878877 The object identifier (object ID) of a row. This column is only
879878 present if the table was created using <literal>WITH
880879 OIDS</literal>, or if the <xref linkend="guc-default-with-oids">
881- configuration variable was set. This column is of type
880+ configuration variable was set at the time . This column is of type
882881 <type>oid</type> (same name as the column); see <xref
883882 linkend="datatype-oid"> for more information about the type.
884883 </para>
@@ -1017,7 +1016,7 @@ CREATE TABLE order_items (
10171016 </listitem>
10181017 <listitem>
10191018 <para>
1020- The tables in question should be created using <literal>WITH
1019+ Of course, the tables in question must be created <literal>WITH
10211020 OIDS</literal>. As of <productname>PostgreSQL</productname> 8.1,
10221021 <literal>WITHOUT OIDS</> is the default.
10231022 </para>
@@ -1096,7 +1095,7 @@ CREATE TABLE order_items (
10961095
10971096 All these actions are performed using the
10981097 <xref linkend="sql-altertable" endterm="sql-altertable-title">
1099- command.
1098+ command, which see for details beyond those given here .
11001099 </para>
11011100
11021101 <sect2>
@@ -1129,6 +1128,18 @@ ALTER TABLE products ADD COLUMN description text CHECK (description <> '')
11291128 constraints later (see below) after you've filled in the new column
11301129 correctly.
11311130 </para>
1131+
1132+ <tip>
1133+ <para>
1134+ Adding a column with a default requires updating each row of the
1135+ table (to store the new column value). However, if no default is
1136+ specified, <productname>PostgreSQL</productname> is able to avoid
1137+ the physical update. So if you intend to fill the column with
1138+ mostly nondefault values, it's best to add the column with no default,
1139+ insert the correct values using <command>UPDATE</>, and then add any
1140+ desired default as described below.
1141+ </para>
1142+ </tip>
11321143 </sect2>
11331144
11341145 <sect2>
@@ -1376,16 +1387,18 @@ ALTER TABLE products RENAME TO items;
13761387<programlisting>
13771388GRANT UPDATE ON accounts TO joe;
13781389</programlisting>
1379- To grant a privilege to a group, use this syntax:
1380- <programlisting>
1381- GRANT SELECT ON accounts TO GROUP staff;
1382- </programlisting>
1383- The special <quote>user</quote> name <literal>PUBLIC</literal> can
1384- be used to grant a privilege to every user on the system. Writing
1385- <literal>ALL</literal> in place of a specific privilege grants all
1390+ Writing <literal>ALL</literal> in place of a specific privilege grants all
13861391 privileges that are relevant for the object type.
13871392 </para>
13881393
1394+ <para>
1395+ The special <quote>user</quote> name <literal>PUBLIC</literal> can
1396+ be used to grant a privilege to every user on the system. Also,
1397+ <quote>group</> roles can be set up to help manage privileges when
1398+ there are many users of a database — for details see
1399+ <xref linkend="user-manag">.
1400+ </para>
1401+
13891402 <para>
13901403 To revoke a privilege, use the fittingly named
13911404 <command>REVOKE</command> command:
@@ -1890,7 +1903,7 @@ REVOKE CREATE ON SCHEMA public FROM PUBLIC;
18901903 </indexterm>
18911904
18921905 <para>
1893- <productname>PostgreSQL</productname> implements table inheritance
1906+ <productname>PostgreSQL</productname> implements table inheritance,
18941907 which can be a useful tool for database designers. (SQL:1999 and
18951908 later define a type inheritance feature, which differs in many
18961909 respects from the features described here.)
@@ -2064,11 +2077,7 @@ VALUES ('New York', NULL, NULL, 'NY');
20642077 Table inheritance is typically established when the child table is
20652078 created, using the <literal>INHERITS</> clause of the
20662079 <xref linkend="sql-createtable" endterm="sql-createtable-title">
2067- statement. However the related statement <command>CREATE TABLE AS</command>
2068- does not allow inheritance to be specified.
2069- </para>
2070-
2071- <para>
2080+ statement.
20722081 Alternatively, a table which is already defined in a compatible way can
20732082 have a new parent relationship added, using the <literal>INHERIT</literal>
20742083 variant of <xref linkend="sql-altertable" endterm="sql-altertable-title">.
@@ -2294,8 +2303,6 @@ VALUES ('New York', NULL, NULL, 'NY');
22942303 </listitem>
22952304 </varlistentry>
22962305 </variablelist>
2297-
2298- Hash partitioning is not currently supported.
22992306 </para>
23002307 </sect2>
23012308
0 commit comments