11<!--
2- $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.57 2001/08/07 22:41:49 petere Exp $
2+ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.58 2001/08/16 20:38:53 tgl Exp $
33-->
44
55 <chapter id="datatype">
@@ -199,10 +199,16 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.57 2001/08/07 22:41:49 pe
199199
200200 <row>
201201 <entry><type>serial</type></entry>
202- <entry></entry>
202+ <entry><type>serial4</type>< /entry>
203203 <entry>autoincrementing four-byte integer</entry>
204204 </row>
205205
206+ <row>
207+ <entry><type>serial8</type></entry>
208+ <entry></entry>
209+ <entry>autoincrementing eight-byte integer</entry>
210+ </row>
211+
206212 <row>
207213 <entry><type>text</type></entry>
208214 <entry></entry>
@@ -394,10 +400,17 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.57 2001/08/07 22:41:49 pe
394400 </row>
395401
396402 <row>
397- <entry>serial </entry>
403+ <entry>serial4 </entry>
398404<entry>4 bytes</entry>
399405<entry>Identifier or cross-reference</entry>
400- <entry>0 to +2147483647</entry>
406+ <entry>1 to 2147483647</entry>
407+ </row>
408+
409+ <row>
410+ <entry>serial8</entry>
411+ <entry>8 bytes</entry>
412+ <entry>Identifier or cross-reference</entry>
413+ <entry>1 to 9223372036854775807</entry>
401414 </row>
402415 </tbody>
403416 </tgroup>
@@ -413,17 +426,27 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.57 2001/08/07 22:41:49 pe
413426 </para>
414427
415428 <para>
416- The <type>bigint</type> type may not be available on all platforms since
417- it relies on compiler support for eight-byte integers.
429+ The <type>bigint</type> type may not function correctly on all platforms,
430+ since it relies on compiler support for eight-byte integers. On a machine
431+ without such support, <type>bigint</type> acts the same
432+ as <type>integer</type> (but still takes up eight bytes of storage).
418433 </para>
419434
420435 <sect2 id="datatype-serial">
421- <title>The SerialType </title>
436+ <title>The SerialTypes </title>
422437
423438 <indexterm zone="datatype-serial">
424439 <primary>serial</primary>
425440 </indexterm>
426441
442+ <indexterm zone="datatype-serial">
443+ <primary>serial4</primary>
444+ </indexterm>
445+
446+ <indexterm zone="datatype-serial">
447+ <primary>serial8</primary>
448+ </indexterm>
449+
427450 <indexterm>
428451 <primary>auto-increment</primary>
429452 <see>serial</see>
@@ -435,9 +458,9 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.57 2001/08/07 22:41:49 pe
435458 </indexterm>
436459
437460 <para>
438- The <type>serial</type>type is a special-case type constructed by
439- <productname>Postgres</productname> from other existing components.
440- It is typically used to create unique identifiers for table entries .
461+ The <type>serial</type>datatypes are not truly types, but are a
462+ notational convenience for setting up unique identifier columns
463+ in tables .
441464 In the current implementation, specifying
442465
443466 <programlisting>
@@ -449,18 +472,33 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceabl
449472 <programlisting>
450473CREATE SEQUENCE <replaceable class="parameter">tablename</replaceable>_<replaceable class="parameter">colname</replaceable>_seq;
451474CREATE TABLE <replaceable class="parameter">tablename</replaceable>
452- (<replaceable class="parameter">colname</replaceable> integer DEFAULT nextval('<replaceable class="parameter">tablename</replaceable>_<replaceable class="parameter">colname</replaceable>_seq');
453- CREATE UNIQUE INDEX <replaceable class="parameter">tablename</replaceable>_<replaceable class="parameter">colname</replaceable>_key on <replaceable class="parameter">tablename</replaceable> (<replaceable class="parameter">colname</replaceable>);
475+ (<replaceable class="parameter">colname</replaceable> integer DEFAULT nextval('<replaceable class="parameter">tablename</replaceable>_<replaceable class="parameter">colname</replaceable>_seq') UNIQUE NOT NULL;
454476 </programlisting>
455477
478+ Thus, we have created an integer column and arranged for its default
479+ values to be assigned from a sequence generator. UNIQUE and NOT NULL
480+ constraints are applied to ensure that explicitly-inserted values
481+ will never be duplicates, either.
482+
456483 <caution>
457484 <para>
458485 The implicit sequence created for the <type>serial</type> type will
459486 <emphasis>not</emphasis> be automatically removed when the
460487 table is dropped.
461488 </para>
462489 </caution>
490+ </para>
463491
492+ <para>
493+ The type names <type>serial</type> and <type>serial4</type> are
494+ equivalent: both create <type>integer</type> columns. The type
495+ name <type>serial8</type> works just the same way, except that it
496+ creates a <type>bigint</type> column. <type>serial8</type> should
497+ be used if you anticipate use of more than 2^31 identifiers over
498+ the lifetime of the table.
499+ </para>
500+
501+ <para>
464502 Implicit sequences supporting the <type>serial</type> are
465503 not automatically dropped when a table containing a serial type
466504 is dropped. So, the following commands executed in order will likely fail: