SERIAL type in RULES

From: Alex Guryanow <gav(at)nlr(dot)ru>
To: pgsql-general(at)postgresql(dot)org
Subject: SERIAL type in RULES
Date: 2000-09-08 10:17:08
Message-ID: 18595.000908@nlr.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

HI,

I use postgresql-7.0.2. One of my tables contains a field of type SERIAL:

CREATE TABLE test2 (id serial, word varchar(100));

another table contains similar fields:

CREATE TABLE test3 (test2_id int4, wod varchar(100));

I want to create a rule, that copies into test3 all what user inserts into test2:

CREATE RULE rule_insert_test2 AS ON INSERT TO test2
DO INSERT INTO test3 (test2_id, word) VALUES (new.id, new.word);

But when I insert into test2 I receive strange results. Here is a dump:

test_db=# insert into test2 (word) values ('alex');
INSERT 12706507 1
test_db=# select * from test3;
test2_id | word
----------+------
1 | alex
(1 row)

test_db=# select * from test2;
id | word
----+------
2 | alex
(1 row)

As you can see test3.test2_id = 1 while test2.id = 2. It seems that the rule receives the correct
value of new.id but after that the sequence for test2 is changed once more. Why this happens? Is
this a bug?

Regards,
Alex

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Enrico Comini 2000-09-08 10:42:34 JDBC
Previous Message Oliver Smith 2000-09-08 07:09:28 Re: That killer 3rd join...