Table of Contents
Sequence Manipulation Functions
This section describes Valentina DB functions for operating on sequence objects.
Sequence objects (also called sequence generators or just sequences) are special Schema objects created with CREATE SEQUENCE command. A sequence object is usually used to generate unique identifiers (Primary Keys) for rows of a table. The sequence functions, provide simple, multiuser-safe methods for obtaining successive sequence values from sequence objects.
See page CREATE SEQUENCE for more details about sequences and examples of usage.
nextval( name )
Advance the sequence object to its next value and return that value. This is done atomically: even if multiple sessions execute nextval concurrently, each will safely receive a distinct sequence value.
INSERT INTO tblPerson( fldID, fldFirstName, fldLastName ) VALUES( NEXTVAL('seqPersonID'), 'Peter', 'Peterson' );
currval( name )
Returns the value most recently obtained by nextval for this sequence in the current session. (An error is reported if nextval has never been called for this sequence in this session.) Notice that because this is returning a session-local value, it gives a predictable answer whether or not other sessions have executed nextval since the current session did.
INSERT INTO tblPerson( fldID, fldFirstName, fldLastName ) VALUES( NEXTVAL('seqPersonID'), 'Peter', 'Peterson' ); INSERT INTO tblPhone( fldID, fldNumber, fldPersonPtr ) VALUES( NEXTVAL('seqPhoneID'), '1111111', CURRVAL('seqPersonID') );
setval( name, new_val )
Reset the sequence object's counter value.
SELECT SETVAL( 'serial', 10000 );