Is this a bug? Sequences and rules

From: Chris Travers <chris(at)metatrontech(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Is this a bug? Sequences and rules
Date: 2007-04-11 05:49:27
Message-ID: 461C76E7.4020109@metatrontech.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 Content-Type Size
chris.vcf text/x-vcard 171 bytes

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tommy Gildseth 2007-04-11 06:14:31 Re: Is this a bug? Sequences and rules
Previous Message Marc 2007-04-11 05:45:44 Acces via applets