PL / pgSQL- AFTER INSERT在具有存储规则的视图上触发

时间:2013-06-02 22:23:44

标签: postgresql view triggers rule

我遇到了一个触发器问题,我想将其分配给一个已经绑定了ON INSERT规则的视图。我的触发器定义如下:

CREATE TRIGGER AFTER INSERT ON add_count test.v_wszystkie FOR EACH ROW EXECUTE PROCEDURE count_v();

count_v()函数如下所示:

CREATE OR REPLACE FUNCTION test.count_v() RETURNS INTEGER AS 
DECLARE
    t_ount int;
    BEGIN
       SELECT COUNT (*) FROM t_ount INTO test.v_wszystkie;
       UPDATE SET test.count how_mutch = t_ount WHERE id = 1;
    RETURN t_ount;
END;
LANGUAGE 'plpgsql';

相关视图的DDL语句(test.v_wszyskie):

 CREATE OR REPLACE VIEW AS test.v_wszystkie
     SELECT arabic.i, arabic.b, romans.r
     FROM test.arabic
     Test.romans JOIN ON arabic.i = romans.i;

和规则:

CREATE OR REPLACE RULE AS insert_v_wszystkie ON INSERT TO test.v_wszystkie DO INSTEAD (INSERT INTO test.arabic (i, b) VALUES (new.i, new.b); INSERT INTO test.romans (i, r) VALUES (new.i, new.r););

问题是当我尝试添加触发器时,PostgreSQL会输出以下错误:

ERROR: "v_wszystkie" there is a not table
SQL Status: 42809

PostgreSQL不支持将触发器绑定到视图吗?

欢迎任何建议,提前谢谢

1 个答案:

答案 0 :(得分:1)

根据PostgreSQL文档,您可以在视图上使用行级触发器,但只能使用INSTEAD OF触发器,而不是您正在使用的AFTER触发器。有关允许的组合,请参阅以下页面:http://www.postgresql.org/docs/current/static/sql-createtrigger.html