有关规则的问题 [英] questions on rules
问题描述
我正在尝试设置一些基本规则来记录插入,更新和
删除继承层次结构中的表(通过将记录
插入到日志表),我有几个问题。
(1)是否有可能在基表上创建一个规则并拥有它
是否适用于所有派生表?我想在基表上创建3个规则
(插入/更新/删除),并将它们应用于所有
继承表。可以这样做吗?
(2)我有一个非常简单的更新规则 - 创建规则log_updates就像在/ b $ b更新到foo do insert到audit_log(table_oid,id,log_what)值
(foo.tableoid,NEW.foo_id,''U'');我曾希望这会在我的audit_log表中为每一行更新创建一个
单个条目。但是,对于foo中的每条记录,它似乎都会触发
。表,即使更新
只影响了一行!我做错了什么?
非常感谢任何帮助。谢谢!
Tim Perrigo
---------------------- -----(播出结束)---------------------------
提示8:解释分析是你的朋友
2004年4月26日星期一20:12,Timothy Perrigo写道:I '我试图设置一些基本规则来记录对继承层次结构中的表的插入,更新和删除(通过将记录插入到日志表中),我有一对问题。
我想你想看一下触发器而不是规则。
-
Richard Huxton
Archonet Ltd
---------------------- -----(播出结束)---------------------------
提示2:你可以使用取消注册命令立即取消所有列表
(将取消注册YourEmailAddressHere发送到 ma ** ***** @ PostgreSQL的.org )
2004年4月26日星期一20:12,Timothy Perrigo写道:我''我试图设置一些基本规则来记录对继承层次结构中的表的插入,更新和删除(通过将记录插入到日志表中),我有几个问题。
我想你想看一下触发器而不是规则。
-
Richard Huxton
Archonet Ltd
------------------------ ---(广播结束)---------------------------
提示2:你可以下车使用取消注册命令一次性列出所有列表
(发送" unregister YourEmailAddressHere" ma*******@postgresql.org )
感谢您的回复。你知道在基表上定义的触发器是否会为继承表上的操作触发
fire? (即,如果我在表格base上有一个后来的
插入触发器,并且从base继承
的表derived将插入到派生的原因中触发器基于
fire?)如果是这样(这是我想要的行为),有没有办法让
得到表的tableoid导致引发火灾?
我非常感谢你的帮助。
Tim
4月27日,2004年,上午7:26,Richard Huxton写道:
2004年4月26日星期一20:12,Timothy Perrigo写道:我是尝试设置一些基本规则来记录对继承层次结构中的表的插入,更新和删除(通过将记录插入到日志表中),我有几个问题。
我想你想看一下触发器而不是规则。
-
Richard Huxton
Archonet Ltd
---------------------------(播出结束)------------ ---------------
提示7:别忘了增加免费空间地图设置
I''m trying to set up some basic rules to log inserts, updates, and
deletes to tables in an inheritance hierarchy (by inserting records
into a log table), and I''ve got a couple of questions.
(1) Is it possible to create a rule on a base table and have it
operate for all derived tables? I''d like to just create 3 rules
(insert/update/delete) on the base table and have them apply to all
inherited tables. Can this be done?
(2) I''ve got a very simple update rule-- create rule log_updates as on
update to foo do insert into audit_log(table_oid, id, log_what) values
(foo.tableoid, NEW.foo_id, ''U''); I had hoped that this would create a
single entry in my audit_log table for each row updated. However, it
seems to fire for each record in the "foo" table, even if the update
affected only one row! What am I doing wrong?
Any help would be very much appreciated. Thanks!
Tim Perrigo
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend
On Monday 26 April 2004 20:12, Timothy Perrigo wrote:I''m trying to set up some basic rules to log inserts, updates, and
deletes to tables in an inheritance hierarchy (by inserting records
into a log table), and I''ve got a couple of questions.
I think you want to look at triggers rather than rules here.
--
Richard Huxton
Archonet Ltd
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)
On Monday 26 April 2004 20:12, Timothy Perrigo wrote:I''m trying to set up some basic rules to log inserts, updates, and
deletes to tables in an inheritance hierarchy (by inserting records
into a log table), and I''ve got a couple of questions.
I think you want to look at triggers rather than rules here.
--
Richard Huxton
Archonet Ltd
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)
Thanks for the reply. Do you know if triggers defined on a base table
fire for operations on inherited tables? (I.e., if I have an after
insert trigger on table "base", and a table "derived" that inherits
from base, will inserts into derived cause the trigger on base to
fire?) If so (this is the behavior I would like), is there a way to
get the tableoid of the table which caused the trigger to fire?
I really appreciate the assistance.
Tim
On Apr 27, 2004, at 7:26 AM, Richard Huxton wrote:
On Monday 26 April 2004 20:12, Timothy Perrigo wrote:I''m trying to set up some basic rules to log inserts, updates, and
deletes to tables in an inheritance hierarchy (by inserting records
into a log table), and I''ve got a couple of questions.
I think you want to look at triggers rather than rules here.
--
Richard Huxton
Archonet Ltd
---------------------------(end of broadcast)---------------------------
TIP 7: don''t forget to increase your free space map settings
这篇关于有关规则的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!