Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d4f4b97

Browse files
committed
Sequences are now based on int8, not int4, arithmetic. SERIAL pseudo-type
has an alias SERIAL4 and a sister SERIAL8. SERIAL8 is just the same except the created column is type int8 not int4. initdb forced. Note this also breaks any chance of pg_upgrade from 7.1, unless we hack up pg_upgrade to drop and recreate sequences. (Which is not out of the question, but I don't wanna do it.)
1 parent bcb0ccf commit d4f4b97

File tree

21 files changed

+254
-182
lines changed

21 files changed

+254
-182
lines changed

contrib/spi/autoinc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,13 @@ autoinc(PG_FUNCTION_ARGS)
7979
seqname = DirectFunctionCall1(textin,
8080
CStringGetDatum(args[i]));
8181
newvals[chnattrs] = DirectFunctionCall1(nextval, seqname);
82+
/* nextval now returns int64; coerce down to int32 */
83+
newvals[chnattrs] = Int32GetDatum((int32) DatumGetInt64(newvals[chnattrs]));
8284
if (DatumGetInt32(newvals[chnattrs]) == 0)
85+
{
8386
newvals[chnattrs] = DirectFunctionCall1(nextval, seqname);
87+
newvals[chnattrs] = Int32GetDatum((int32) DatumGetInt64(newvals[chnattrs]));
88+
}
8489
pfree(DatumGetTextP(seqname));
8590
chnattrs++;
8691
i++;

doc/src/sgml/datatype.sgml

Lines changed: 50 additions & 12 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.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 Serial Type</title>
436+
<title>The Serial Types</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>
450473
CREATE SEQUENCE <replaceable class="parameter">tablename</replaceable>_<replaceable class="parameter">colname</replaceable>_seq;
451474
CREATE 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:

doc/src/sgml/ref/create_sequence.sgml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_sequence.sgml,v 1.17 2001/06/30 22:01:17 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_sequence.sgml,v 1.18 2001/08/16 20:38:53 tgl Exp $
33
Postgres documentation
44
-->
55

@@ -79,7 +79,7 @@ CREATE [ TEMPORARY | TEMP ] SEQUENCE <replaceable class="parameter">seqname</rep
7979
The optional clause <option>MINVALUE
8080
<replaceable class="parameter">minvalue</replaceable></option>
8181
determines the minimum value
82-
a sequence can generate. The defaults are 1 and -2147483647 for
82+
a sequence can generate. The defaults are 1 and -2^63-1 for
8383
ascending and descending sequences, respectively.
8484
</para>
8585
</listitem>
@@ -92,7 +92,7 @@ CREATE [ TEMPORARY | TEMP ] SEQUENCE <replaceable class="parameter">seqname</rep
9292
The optional clause <option>MAXVALUE
9393
<replaceable class="parameter">maxvalue</replaceable></option>
9494
determines the maximum
95-
value for the sequence. The defaults are 2147483647 and -1 for
95+
value for the sequence. The defaults are 2^63-1 and -1 for
9696
ascending and descending sequences, respectively.
9797
</para>
9898
</listitem>

src/backend/commands/creatinh.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.79 2001/08/10 18:57:34 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.80 2001/08/16 20:38:53 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -447,7 +447,6 @@ MergeAttributes(List *schema, List *supers, bool istemp,
447447
typename->typmod = attribute->atttypmod;
448448
def->typename = typename;
449449
def->is_not_null = attribute->attnotnull;
450-
def->is_sequence = false;
451450
def->raw_default = NULL;
452451
def->cooked_default = NULL;
453452
def->constraints = NIL;

0 commit comments

Comments
 (0)