seq. DEFAULT values and rules
Is this a bug ?, the new.a_id in my opinion should not be replaced here with nextval () function but with the actual value returned by the sequence. Please have this minimal example .
CREATE TABLE a
(
a_id serial primary key
);
CREATE TABLE b
(
b_id serial Primary key
);
CREATE TABLE a_b
(
a_id INTEGER REFERENCES a (a_id),
b_id INTEGER REFERENCES b (b_id)
);
INSERT INTO b SELECT n FROM generate_series(1,10) AS n;
CREATE RULE a_a_b_insert AS ON INSERT TO a DO INSERT INTO a_b SELECT new.a_id , b_id FROM b;
INSERT INTO a (a_id) VALUES (DEFAULT);
salah jubeh <s_jubeh@yahoo.com> writes:
Is this a bug ?
No, it's a documented, operating-as-designed behavior. Rules are macros
and therefore have all the usual multiple-evaluation-of-arguments
hazards.
If you just want to propagate data from one table to another, a trigger
is often a better choice, or at least one with fewer surprises.
regards, tom lane
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general