4 CREATE SEQUENCE next_id START -2 MINVALUE -2;
11 CREATE TRIGGER ids_nextid
12 BEFORE INSERT OR UPDATE ON ids
14 EXECUTE PROCEDURE autoinc (id, next_id);
16 INSERT INTO ids VALUES (0, 'first (-2 ?)');
17 INSERT INTO ids VALUES (null, 'second (-1 ?)');
18 INSERT INTO ids(idesc) VALUES ('third (1 ?!)');
22 UPDATE ids SET id = null, idesc = 'first: -2 --> 2'
23 WHERE idesc = 'first (-2 ?)';
24 UPDATE ids SET id = 0, idesc = 'second: -1 --> 3'
26 UPDATE ids SET id = 4, idesc = 'third: 1 --> 4'
31 SELECT 'Wasn''t it 4 ?' as nextval, nextval ('next_id') as value;
33 insert into ids (idesc) select textcat (idesc, '. Copy.') from ids;