In the object hierarchy under every schema are Sequences. You can add sequences by selecting CREATE SEQUENCE from the Sequences context menu. Once a sequence has been created, it can be renamed, commented on, altered, and dropped, and its privileges can be edited. This section describes how to create, manage, and drop a sequence with Administrator.
PostgreSQL allows you to create sequences on a database in a schema. A sequence is a number generator that is restricted by various values such as start value, minimum value, maximum value, and increment. Each time the sequence is called upon, it returns the next acceptable number, given the restrictions in the definition of the sequence.
In this example, you will create a sequence named invoice_sequence.
A sequence is an object under a schema, so to create a sequence, first expand the database you wish to create the sequence under (click the [O-] beside the database name), then expand the public schema.
Right-click on Sequences and select CREATE SEQUENCE.
In the Name For The New Sequence field, type: invoice_sequence
Select the direction in which the sequence progresses. For this example, use Ascending as the direction.
Select the Increment. Each time the sequence is accessed, it generates a new number that differs from the previous number by this amount. For this example, set the Increment to 5.
Set the MinValue, the minimum value that the sequence can generate. For this example, set the MinValue to 0.
Set the MaxValue, the maximum value that the sequence can generate. For this example, set the MaxValue to 100000.
Set the Start value, the number generated by the sequence when it is invoked for the first time. For this example, set the Start value to 20.
Set the Cache, the number of values to be computed and stored in memory to prevent any slowdowns due to realtime computations. For this example, set Cache to 3.
Cache should be used very carefully; its use may generate unexpected results in certain cases. For example, when two backends are using the same sequence object, they each cache the values and change the sequence object. As a result, the sequence may not produce the expected results. Refer to the PostgreSQL 7.3 Reference Manual for further details.
Set whether the sequence should Cycle. If this box is checked, the sequence values restart once the MaxValue (for Ascending Sequences) or the MinValue (for Descending Sequences) has been reached. For this example, check the Cycle box.
Click OK to create the sequence.
Note that the sequence invoice_sequence has been added under the Sequences node in the Tree View.
Administrator also enables you to perform the following operations on an existing sequence:
By default, the user creating the sequence is the owner. However, the owner can later be modified by a superuser. To modify the owner of a sequence, right-click on the sequence and select ALTER SEQUENCE OWNER. A dialog asks for the new owner name. Because the owner name can be only one of the users in the cluster, the dialog has a drop down box from which the user can be selected. Once the username is selected, click OK.
PostgreSQL allows commenting on sequences, which makes them easier to identify. To comment on a sequence, right click on it, and select COMMENT. A dialog pops up asking for the comment. If there is already a comment on the sequence, this comment is displayed. Type the new comment in the edit box and click OK to save it.
To drop a sequence, right-click on it and select either DROP RESTRICT or DROP CASCADE. DROP RESTRICT will not drop the sequence if there are any dependent objects. DROP CASCADE automatically drops the sequence and all objects that depend on it.
If Preferences => Ask For Confirmations is enabled, you are asked to confirm that you want the sequence dropped (and all the dependent objects in case of a DROP CASCADE); if it is disabled, the sequence is dropped immediately (along with its dependent objects if DROP CASCADE was selected). This action cannot be undone.
To rename a sequence, right-click on it and select RENAME SEQUENCE. Type the new name in the dialog that appears and click OK.