|
| 1 | +.\" This is -*-nroff-*- |
| 2 | +.\" XXX standard disclaimer belongs here.... |
| 3 | +.\" $Header: /cvsroot/pgsql/src/man/Attic/create_sequence.l,v 1.1 1997/04/02 04:19:58 vadim Exp $ |
| 4 | +.TH "CREATE SEQUENCE" SQL 04/01/97 PostgreSQL PostgreSQL |
| 5 | +.SH NAME |
| 6 | +create sequence \(em create a new sequence number generator |
| 7 | +.SH SYNOPSIS |
| 8 | +.nf |
| 9 | +\fBcreate sequence\fR seqname |
| 10 | + [\fBincrement\fP incby_value] |
| 11 | + [\fBminvalue\fP min_value] |
| 12 | + [\fBmaxvalue\fP max_value] |
| 13 | + [\fBstart\fP start_value] |
| 14 | + [\fBcache\fP cache_value] |
| 15 | + [\fBcycle\fP] |
| 16 | +.fi |
| 17 | +.SH DESCRIPTION |
| 18 | +.BR "Create sequence" |
| 19 | +will enter a new sequence number generator into the current data base. |
| 20 | +Actually, new single block |
| 21 | +.BR table |
| 22 | +with name |
| 23 | +.IR seqname |
| 24 | +will be created and initialized. |
| 25 | +The generator will be |
| 26 | +\*(lqowned\*(rq by the user issuing the command. |
| 27 | +.PP |
| 28 | +The |
| 29 | +.BR "increment" |
| 30 | +is optional clause. Positive value will make ascending sequence, |
| 31 | +negative - descending. Default value is 1. |
| 32 | +.PP |
| 33 | +The optional integer |
| 34 | +.BR minvalue |
| 35 | +determines the minimum value a sequence can be. Defaults are |
| 36 | +1/-2147483647 for ascending/descending sequences. |
| 37 | +.PP |
| 38 | +Use optional integer |
| 39 | +.BR maxvalue |
| 40 | +to determine the maximum value for sequence. Defaults are |
| 41 | +2147483647/-1 for ascending/descending sequences. |
| 42 | +.PP |
| 43 | +The optinal |
| 44 | +.BR "start" |
| 45 | +value enables sequence to begin anywhere. Default is |
| 46 | +.BR minvalue |
| 47 | +for ascending sequences and |
| 48 | +.BR maxvalue |
| 49 | +for descending ones. |
| 50 | +.PP |
| 51 | +The |
| 52 | +.BR cache |
| 53 | +option enables sequence numbers to be preallocated and |
| 54 | +stored in memory for faster access. The minimum value is 1 |
| 55 | +(i.e. - no cache) and it is default. |
| 56 | +.BR NOTE: |
| 57 | +each backend uses own cache to store allocated numbers. |
| 58 | +Cached but not used in current session numbers will be lost. |
| 59 | +.PP |
| 60 | +The optional |
| 61 | +.BR cycle |
| 62 | +keyword may be used to enable sequence to continue when the |
| 63 | +.BR maxvalue/minvalue |
| 64 | +has been reached by ascending/descending sequence. |
| 65 | +If the limit is reached, the next number generated will be |
| 66 | +whatever the |
| 67 | +.BR minvalue/maxvalue |
| 68 | +is. |
| 69 | +.PP |
| 70 | +After sequence created, You may use function |
| 71 | +.BR nextval |
| 72 | +with sequence name as argument to get new number from sequence |
| 73 | +specified. |
| 74 | +To determine the current sequence number use function |
| 75 | +.BR currval |
| 76 | +('sequence_name'). |
| 77 | +.BR NOTE: |
| 78 | +after sequence creation You are to call |
| 79 | +.BR nextval |
| 80 | +before first call to |
| 81 | +.BR currval. |
| 82 | +.PP |
| 83 | +.nf |
| 84 | +Use query like |
| 85 | + |
| 86 | +select * from <sequence_name>; |
| 87 | + |
| 88 | +to get parameters of a sequence. |
| 89 | +.fi |
| 90 | +.PP |
| 91 | +Low-level locking is used to enable multiple simultaneous calls |
| 92 | +to a generator. |
| 93 | +.PP |
| 94 | +.SH EXAMPLES |
| 95 | +.nf |
| 96 | +-- |
| 97 | +-- Create sequence seq caching 2 numbers, starting with 10 |
| 98 | +-- |
| 99 | +create sequence seq cache 2 start 10; |
| 100 | +.fi |
| 101 | +.nf |
| 102 | +-- |
| 103 | +-- Select next number from sequence |
| 104 | +-- |
| 105 | +select nextval ('seq'); |
| 106 | +.fi |
| 107 | +.nf |
| 108 | +-- |
| 109 | +-- Use sequence in insert |
| 110 | +-- |
| 111 | +insert into table _table_ values (nextval ('seq'),...); |
| 112 | +.fi |
| 113 | +.SH "SEE ALSO" |
| 114 | +drop sequence(l). |
0 commit comments