Search Postgresql Archives

Is this a bug? Sequences and rules

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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:chris@xxxxxxxxxxxxxxxx
tel;work:509-888-0220
tel;cell:509-630-7794
x-mozilla-html:FALSE
version:2.1
end:vcard


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux