Hi;

I noticed that rules were not behaving properly. I created a test case, and it looks like the sequence is getting double-incrimented. Is this the way this is supposed to work?

I know triggers would be better for something like this but I find these results... surprising....

Version is 8.1.4

postgres=# create table test1 (id serial, test text);
NOTICE: CREATE TABLE will create implicit sequence "test1_id_seq" for serial column "test1.id"
CREATE TABLE
postgres=# create table test2 (id int);
CREATE TABLE
postgres=# create rule insert as on insert to test1 do also insert into test2 (id) values (new.id);
CREATE RULE

postgres=# insert into test1 (test) values (1);
INSERT 0 1
postgres=# insert into test1 (test) values (1);
INSERT 0 1
postgres=# insert into test1 (test) values (1);
INSERT 0 1
postgres=# select * from test1;
id | test
----+------
 1 | 1
 3 | 1
 5 | 1
(3 rows)

postgres=# select * from test2;
id
----
 2
 4
 6
(3 rows)
begin:vcard
fn:Chris Travers
n:Travers;Chris
email;internet:[EMAIL PROTECTED]
tel;work:509-888-0220
tel;cell:509-630-7794
x-mozilla-html:FALSE
version:2.1
end:vcard

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
       choose an index scan if your joining column's datatypes do not
       match

Reply via email to