When a table is inherited, sequence doesn't increase by 1 but by more than 1.
For example, let be defined table
parent with
Code:
CREATE TABLE parent(id serial, message text);
and two tables inheriting
parent Code:
CREATE TABLE child1(CHECK(id >= 1 AND id <= 100)) INHERITS(parent);
CREATE TABLE child2(CHECK(id >= 101 AND id <= 200)) INHERITS(parent);
Also, default
id values are dropped for child tables
Code:
ALTER TABLE child1 ALTER id DROP DEFAULT;
ALTER TABLE child2 ALTER id DROP DEFAULT;
Finally, two rules are created to put rows into table
child1 when 1 <=
id <= 100 or into table
child2 when 101 <=
id <= 200:
Code:
CREATE OR REPLACE RULE r1 AS ON INSERT TO parent WHERE (id >=1 AND id <= 100) DO INSTEAD
INSERT INTO child1 VALUES(NEW.id, NEW.message);
CREATE OR REPLACE RULE r2 AS ON INSERT TO parent WHERE (id >=101 AND id <= 200) DO INSTEAD
INSERT INTO child2 VALUES(NEW.id, NEW.message);
When two rows are put into parent table with
Code:
INSERT INTO parent(message) VALUES('Test 1');
INSERT INTO parent(message) VALUES('Test 2');
they are inserted with
id values of 6 and 12. If I continue to insert them, each row has
id incremented by 6 instead by 1. Where's the problem?
(Remark: no other users, processes etc., it is test database created just to check out this problem.)