From 2ea5b06c7a7056dca0af1610aadebe608fbcca08 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Fri, 10 Feb 2017 15:12:32 -0500 Subject: Add CREATE SEQUENCE AS clause This stores a data type, required to be an integer type, with the sequence. The sequences min and max values default to the range supported by the type, and they cannot be set to values exceeding that range. The internal implementation of the sequence is not affected. Change the serial types to create sequences of the appropriate type. This makes sure that the min and max values of the sequence for a serial column match the range of values supported by the table column. So the sequence can no longer overflow the table column. This also makes monitoring for sequence exhaustion/wraparound easier, which currently requires various contortions to cross-reference the sequences with the table columns they are used with. This commit also effectively reverts the pg_sequence column reordering in f3b421da5f4addc95812b9db05a24972b8fd9739, because the new seqtypid column allows us to fill the hole in the struct and create a more natural overall column ordering. Reviewed-by: Steve Singer Reviewed-by: Michael Paquier --- doc/src/sgml/ref/create_sequence.sgml | 36 ++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'doc/src/sgml/ref/create_sequence.sgml') diff --git a/doc/src/sgml/ref/create_sequence.sgml b/doc/src/sgml/ref/create_sequence.sgml index 86ff018c4b..f1448e7ab3 100644 --- a/doc/src/sgml/ref/create_sequence.sgml +++ b/doc/src/sgml/ref/create_sequence.sgml @@ -21,7 +21,9 @@ PostgreSQL documentation -CREATE [ TEMPORARY | TEMP ] SEQUENCE [ IF NOT EXISTS ] name [ INCREMENT [ BY ] increment ] +CREATE [ TEMPORARY | TEMP ] SEQUENCE [ IF NOT EXISTS ] name + [ AS data_type ] + [ INCREMENT [ BY ] increment ] [ MINVALUE minvalue | NO MINVALUE ] [ MAXVALUE maxvalue | NO MAXVALUE ] [ START [ WITH ] start ] [ CACHE cache ] [ [ NO ] CYCLE ] [ OWNED BY { table_name.column_name | NONE } ] @@ -110,6 +112,21 @@ SELECT * FROM name; + + data_type + + + The optional + clause AS data_type + specifies the data type of the sequence. Valid types are + are smallint, integer, + and bigint. bigint is the + default. The data type determines the default minimum and maximum + values of the sequence. + + + + increment @@ -132,9 +149,8 @@ SELECT * FROM name; class="parameter">minvalue determines the minimum value a sequence can generate. If this clause is not supplied or is specified, then - defaults will be used. The defaults are 1 and - -263 for ascending and descending sequences, - respectively. + defaults will be used. The default for an ascending sequence is 1. The + default for a descending sequence is the minimum value of the data type. @@ -148,9 +164,9 @@ SELECT * FROM name; class="parameter">maxvalue determines the maximum value for the sequence. If this clause is not supplied or is specified, then - default values will be used. The defaults are - 263-1 and -1 for ascending and descending - sequences, respectively. + default values will be used. The default for an ascending sequence is + the maximum value of the data type. The default for a descending + sequence is -1. @@ -347,12 +363,6 @@ END; CREATE SEQUENCE conforms to the SQL standard, with the following exceptions: - - - The standard's AS data_type expression is not - supported. - - Obtaining the next value is done using the nextval() -- cgit v1.2.1