Is this a bug? Sequences and rules - Mailing list pgsql-general

From Chris Travers
Subject Is this a bug? Sequences and rules
Date
Msg-id 461C76E7.4020109@metatrontech.com
Whole thread Raw
Responses Re: Is this a bug? Sequences and rules  (Tommy Gildseth <tommy@gildseth.com>)
Re: Is this a bug? Sequences and rules  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
List pgsql-general
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)

Attachment

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: plperl "set-valued function" problem
Next
From: Tommy Gildseth
Date:
Subject: Re: Is this a bug? Sequences and rules