Александр <alexander_8901@mail.ru> writes:
> Strange the rule works for an insertion
This is expected behavior, because the rule works like a macro, and
you have a volatile argument (that is, the nextval() call for the
serial column's default) being passed to it and thereby being executed
twice. IOW, what you wrote is equivalent to
insert into test(id, name)
values
(nextval('test_id_seq'), '1'),
(nextval('test_id_seq'), '2'),
(nextval('test_id_seq'), '3');
and that executes, then the rule causes this to also be executed:
insert into v_test (v_id, v_name)
values
(nextval('test_id_seq'), '1'),
(nextval('test_id_seq'), '2'),
(nextval('test_id_seq'), '3');
What you seem to want would be much more reliably done with a trigger.
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs