对于安全敏感的设计,我想DELETEs
在某些表上禁用。
DELETE
应该只deleted
在一行上设置一个标志(然后在视图上可见,应用层将使用该标志)。
据我了解,规则会生成额外的查询 - 因此规则无法抑制原始查询。
如图一个带触发器的玩具示例(尚未测试):
-- data in this table should be 'undeletable'
CREATE table article (
id serial,
content text not null,
deleted boolean default false
)
-- some view that would only show articles, that are NOT deleted
...
-- toy trigger (not tested)
CREATE OR REPLACE FUNCTION suppress_article_delete()
RETURNS TRIGGER AS $sad$
BEGIN
IF (TG_OP = 'DELETE') THEN
UPDATE article SELECT id, content, TRUE;
-- NEW or NULL??
RETURN NEW;
END IF;
RETURN NULL;
END;
$sad$ LANGUAGE plpgsql;
什么是抑制 a 的好方法DELETE
?