在postgresql中更新触发器后,将值从一个表更新到另一个表

时间:2017-06-13 11:10:42

标签: sql postgresql triggers postgresql-9.3

我有两个表permit_table,其中包含columns builder和permit_number weekly_table with columns applicant和permit_number。 现在,如果来自permit_table的构建器列中有任何更新,我需要使用'旧申请人值+新构建者值'更新weekly_table的申请人列,前提是permit_table中更新的构建者值的许可证编号应与任何许可证编号相匹配。 weekly_table。 我尝试过以下触发器和功能

ESC[36mverboseESC[39m: REQUEST for [PUT] /parse/classes/_Installation   /zKIp8LLOWr: {
                                                                              "GCMSenderId":"diMV6Hm3j07dbqVPEsZRgqNzDo3YvA5zNdUmtO6Q4ka5ijRyyIRHiWCWOBVBDA22OIls-4bO06kxDPuOKFwJUZuMD3Xt41WuKUoOJwBlW7cKdqv9llj7Me0uiWFLWDwS7V",
  "UniqueId": "a59020fff8ca30d00",
  "appVersion": "2.3.3",
  "objectId": "zKIp8LLOWr"
} method=PUT, url=/parse/classes/_Installation/zKIp8LLOWr, x-parse-  app-display-version=2.3.3, x-parse-installation-id=29918e2f-8bbd-4ab7-975f-f854e1f43689, user-agent=Parse Android SDK 1.13.1 (com.mrfizzy/18) API Level 21, connection=Keep-Alive, accept-encoding=gzip, x-parse-os-version=5.0, x-parse-app-build-version=18, content-type=application/json, x-parse-client-key=, x-parse-client-version=a1.13.1, host=46.101.199.219:1337, content-length=245, x-parse-application-id=JHyfl9YhXCQ24r6J8ohdVlHLt1hfWhB4MF2jQAQn, GCMSenderId=diMV6HmLH3I:APA91bFQS4Sq9G5wlej07dbqVPEsZRgqNzDo3YvA5zNdUmtO6Q4ka5ijRyyIRHiWCWOBVBDA22OIls-4bO06kxDPuOKFwJUZuMD3Xt41WuKUoOJwBlW7cKdqv9llj7Me0uiWFLWDwS7V, UniqueId=a59020a48ca30d00, appVersion=2.3.3, objectId=zKIp8LLOWr
ESC[31merrorESC[39m: Error generating response. ParseError { code: 101, message: 'Object not found for update.' } code=101, message=Object not found for update.
[object Object]

触发器是

CREATE OR REPLACE FUNCTION edmonton.automated_builder_update_trigger_manual()
RETURNS trigger AS
$BODY$
DECLARE
    e record;
BEGIN

EXECUTE format('Update weekly_table as a
set applicant = old.applicant||new.builder where old.permit_number = 
a.permit_number');


RETURN NULL;
END;
$BODY$
 LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION edmonton.automated_builder_update_trigger_manual()
OWNER TO postgres;

收到错误'错过表'old'的FROm CLAUSE条目。

1 个答案:

答案 0 :(得分:0)

EXECUTE format('Update weekly_table as a
set applicant = old.applicant||new.builder where old.permit_number = 
a.permit_number');

尝试改为:

EXECUTE format('Update weekly_table as a
set applicant = ($1).applicant||($2).builder where ($1).permit_number  = 
a.permit_number') using old,new;