2017-06-22 116 views
0

我正在存儲從觸發進入一個function.I裏面的變量時,我使用function.Below裏面的變量正在一個錯誤的值是我的功能,引發如何使用變量中功能PLPGSQL

CREATE OR REPLACE FUNCTION 
edm.automated_builder_update_trigger_manual() 
RETURNS trigger AS 
$BODY$ 
DECLARE 
    e record; 
    weekly_permit_table text := TG_ARGV[0]; 
BEGIN 


Update edm.weekly_permit_table as a 
set applicant = applicant||' '||'-'||' '||new.builder where 
old.permit_number = split_part(a.permit_details, ' ',1); 


RETURN NULL; 
END; 

我的觸發

CREATE TRIGGER builder_update_trigger_manual 
AFTER UPDATE 
ON edm.permit_table_manual_05_2017 
FOR EACH ROW 
WHEN (((old.builder)::text IS DISTINCT FROM (new.builder)::text)) 
EXECUTE PROCEDURE 
edm.automated_builder_update_trigger_manual('weekly_permit_report_05_2017'); 

當我更新 'edm.permit_table_manual_05_2017' 表器值,我得到錯誤 '錯誤:關係edm.weekly_permit_table不列入存在'

我知道這可能很愚蠢。但我不確定我在哪裏錯了。

+0

[執行動態命令(https://www.postgresql.org/docs/current/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN) – Abelisto

+0

廣東話我們不使用執行格式? –

+0

執行用戶是否有權寫入此表? – Mokadillion

回答

0
CREATE OR REPLACE FUNCTION edm.automated_builder_update_trigger_manual() 
RETURNS trigger AS 
$BODY$ 
DECLARE 
    e record; 
    weekly_permit_table text := TG_ARGV[0]; 
BEGIN 
    EXECUTE 
    format(
     $q$ 
     UPDATE edm.%I AS a SET 
      applicant = concat(applicant,' - '||$1) 
     WHERE 
      $2 = split_part(a.permit_details, ' ',1)$q$, 
     weekly_permit_table) 
    USING NEW.builder, OLD.permit_number; 
    RETURN NULL; 
END $BODY$; 

About EXECUTE

+0

謝謝你的工作 –