[go: up one dir, main page]

  Top

Name

sequence_set — Sets and returns the state of a sequence object.

Synopsis

integer sequence_set ( in name varchar ,
  in state integer ,
  in mode integer );
 

Description

The function sets and returns the state of a sequence object. The mode specifies whether a check for order of values should be made. If mode equals 0, the state is set regardless of the previous state. If mode is non-zero, the state is changed only if the new state is greater than the previous state. This gives some (weak) protection from occasional 'rewind' the sequence back to values that are already in use.

Parameters

name

The server-wide name of a sequence.

state

A new state of the sequence.

mode

Flags if a new state of the sequence should be ignored if it is less than the current one.

Return Types

The function returns an integer that is equal to what the next call to sequence_next () will return.

Examples

Example 24.368. Different modes of sequence_set()

The sequence of calls demonstrates various calls of sequence_set ().

select sequence_set ('sample', 5, 0);
5

1 Rows. -- 0 msec.

select sequence_next ('sample');
5

1 Rows. -- 0 msec.

select sequence_next ('sample');
6

1 Rows. -- 0 msec.

-- This has no effect because current state(6) is greater than 2.
select sequence_set ('sample', 2, 1);
7

1 Rows. -- 0 msec.

select sequence_next ('sample');
7

1 Rows. -- 0 msec.

-- But this change has effect:
select sequence_set ('sample', 2, 0);
2

1 Rows. -- 0 msec.

select sequence_next ('sample');
2

1 Rows. -- 0 msec.