Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitda1738a

Browse files
committed
This patch improves the documentation for SERIAL columns a little bit.
Neil Conway
1 parent982b26c commitda1738a

File tree

1 file changed

+39
-21
lines changed

1 file changed

+39
-21
lines changed

‎doc/src/sgml/datatype.sgml

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.109 2002/11/21 23:31:20 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.110 2002/12/06 05:17:42 momjian Exp $
33
-->
44

55
<chapter id="datatype">
@@ -654,10 +654,11 @@ NUMERIC
654654
</indexterm>
655655

656656
<para>
657-
The <type>serial</type> data types are not truly types, but are a
658-
notational convenience for setting up unique identifier columns
659-
in tables.
660-
In the current implementation, specifying
657+
The <type>serial</type> data type is not a true type, but merely
658+
a notational convenience for setting up identifier columns
659+
(similar to the <literal>AUTO_INCREMENT</literal> property
660+
supported by some other databases). In the current
661+
implementation, specifying
661662

662663
<programlisting>
663664
CREATE TABLE <replaceable class="parameter">tablename</replaceable> (
@@ -683,33 +684,50 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> (
683684
not automatic.
684685
</para>
685686

687+
<para>
688+
To use a <type>serial</type> column to insert the next value of
689+
the sequence into the table, specify that the <type>serial</type>
690+
column should be assigned the default value. This can be done
691+
either be excluding from the column from the list of columns in
692+
the <command>INSERT</command> statement, or through the use of
693+
the <literal>DEFAULT</literal> keyword.
694+
</para>
695+
686696
<para>
687697
The type names <type>serial</type> and <type>serial4</type> are
688698
equivalent: both create <type>integer</type> columns. The type
689699
names <type>bigserial</type> and <type>serial8</type> work just
690700
the same way, except that they create a <type>bigint</type>
691701
column. <type>bigserial</type> should be used if you anticipate
692-
the use of more than 2<superscript>31</> identifiers over the lifetime of the table.
702+
the use of more than 2<superscript>31</> identifiers over the
703+
lifetime of the table.
693704
</para>
694705

695706
<para>
696-
The sequence created by a <type>serial</type> type is automatically
697-
dropped when
698-
the owning column is dropped, and cannot be dropped otherwise.
699-
(This was not true in <productname>PostgreSQL</productname> releases
700-
before 7.3. Note that this automatic drop linkage will not occur for a
701-
sequence created by reloading a dump from a pre-7.3 database; the dump
702-
file does not contain the information needed to establish the dependency
703-
link.)
707+
The sequence created by a <type>serial</type> type is
708+
automatically dropped when the owning column is dropped, and
709+
cannot be dropped otherwise. (This was not true in
710+
<productname>PostgreSQL</productname> releases before 7.3. Note
711+
that this automatic drop linkage will not occur for a sequence
712+
created by reloading a dump from a pre-7.3 database; the dump
713+
file does not contain the information needed to establish the
714+
dependency link.) Furthermore, this dependency between sequence
715+
and column is made only for the <type>serial</> column itself; if
716+
any other columns reference the sequence (perhaps by manually
717+
calling the <function>nextval()</>) function), they may be broken
718+
if the sequence is removed. Using <type>serial</> columns in
719+
fashion is considered bad form.
704720
</para>
705721

706-
<note><para>
707-
Prior to <productname>PostgreSQL</productname> 7.3, <type>serial</type>
708-
implied <literal>UNIQUE</literal>. This is no longer automatic. If
709-
you wish a serial column to be <literal>UNIQUE</literal> or a
710-
<literal>PRIMARY KEY</literal> it must now be specified, same as with
711-
any other data type.
712-
</para></note>
722+
<note>
723+
<para>
724+
Prior to <productname>PostgreSQL</> 7.3, <type>serial</type>
725+
implied <literal>UNIQUE</literal>. This is no longer automatic.
726+
If you wish a serial column to be <literal>UNIQUE</literal> or a
727+
<literal>PRIMARY KEY</literal> it must now be specified, just as
728+
with any other data type.
729+
</para>
730+
</note>
713731
</sect2>
714732
</sect1>
715733

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp