在postgresql中创建一个触发器

时间:2017-04-25 09:34:58

标签: sql postgresql triggers

我的触发器有问题:

listenChannels

我使用3个表,查询是正确的,所以我认为错误不是来自这里。但是当我在我的终端中复制过去这个触发器时没有发生任何事情,没有错误信息,我可以在终端写入但我无法执行任何查询,就像我在触发器中忘记了一些东西所以我认为它不是完全创造我认为。

我想我混合了我在学校学习的两种语言PL / SQL和postgresql。

谢谢你的帮助

2 个答案:

答案 0 :(得分:0)

我不知道你遇到了什么问题。一个是显而易见的as不用于变量; into是。此外,您应该为变量命名,以便它们不与列名冲突:

CREATE OR REPLACE FUNCTION process_fillDerivedFrom_used() RETURNS TRIGGER AS $fillDerivedFrom_used$
  DECLARE
    prog      v_varchar(255);
    current   v_varchar(255);
  BEGIN
    SELECT u.iduseentity as prog, g.idCreatedEntity as current
    INTO v_proc, v_current
    FROM entity e JOIN
         used u
         ON e.identity = u.iduseentity JOIN
         activity a
         ON a.idactivity = u.idusedactivity JOIN
         generatedby g
         ON g.idcreatoractivity = a.idactivity

    INSERT INTO DERIVEDFROM VALUES (v_prog, v_current)
END;

当然,这就引出了为什么要使用变量的问题:

CREATE OR REPLACE FUNCTION process_fillDerivedFrom_used() RETURNS TRIGGER AS $fillDerivedFrom_used$
  BEGIN
    INSERT INTO DERIVEDFROM (prog, current)  -- or whatever the column names are
        SELECT u.iduseentity as prog, g.idCreatedEntity as current
        FROM entity e JOIN
             used u
             ON e.identity = u.iduseentity JOIN
             activity a
             ON a.idactivity = u.idusedactivity JOIN
             generatedby g
             ON g.idcreatoractivity = a.idactivity;    
END;

答案 1 :(得分:0)

我已经完成了这项工作,谢谢你的帮助!

<router-view :slidePosition="slidePosition" class="view"></router-view>
相关问题