ドキュメントから
そのため、最初に何も実行せずにクエリを書き換えます。
複数のレコードを一度に挿入しない場合でも機能させることができます:
create or replace rule ct_i_children1 as
on insert to Children1
do instead (
insert into Parents(id, attribute1, type)
values(nextval('parents_id_seq'), new.attribute1, 'Child1');
insert into Partial_Children1(id, attribute2, type)
values(currval('parents_id_seq'), new.attribute2, 'Child1');
);
次に、次のことができます。
insert into Children1 (attribute1, attribute2) values ('a1', 'a2');
insert into Children1 (attribute1, attribute2) values ('b1', 'b2');
しかし、そうではありません
insert into Children1 (attribute1, attribute2)
values ('a1', 'a2'),
('b1', 'b2');
したがって、トリッキーなcurrval()呼び出しでルールシステムを使用するべきではありません。
さらに、これらのページのコメントをご覧ください:
- http://www.postgresql.org/docs/ 8.2 / Interactive / rules-update.html
- http://archives.postgresql.org/pgsql- sql / 2004-10 / msg00195.php
- http://archives.postgresql.org/pgsql- general / 2009-06 / msg00278.php
もう1つのヒント:postgresqlメーリングリストでのサポートは、データベースエンジン自体と同じくらい優れています!
ちなみに、postgresqlがすぐに継承をサポートしていることをご存知ですか?
概要:トリガーを使用するか、複数行の挿入を避ける必要があります!