2015-12-08 71 views
0

當我嘗試更新時,出現錯誤。任何幫助,高度讚賞!更新前的PostgreSQL觸發器

CREATE OR REPLACE FUNCTION test_x(value integer) 
    RETURNS trigger AS 
$BODY$ 
DECLARE 

BEGIN 
update backups.scrap_v16_sah_mil_hur_bak set value = '-99' where scrap_durum =1 and (char_length(value) < 5 or value= '' or value is null or value like '%Belir%' ); 

    RETURN value; 
END;$BODY$ 
    LANGUAGE plpgsql VOLATILE 
    COST 100; 


ALTER FUNCTION test_x(value) 
    OWNER TO postgres; 

GRANT EXECUTE ON FUNCTION backups.scrap_v16_sah_mil_hur_bak(value) TO public; 
GRANT EXECUTE ON FUNCTION backups.scrap_v16_sah_mil_hur_bak(value) TO postgres; 

CREATE TRIGGER test_x 
BEFORE UPDATE 
ON backups.scrap_v16_sah_mil_hur_bak 
FOR EACH ROW 
EXECUTE PROCEDURE test_x(); 

該錯誤消息是

ERROR: trigger functions cannot have declared arguments HINT: The arguments of the trigger can be accessed through TG_NARGS and TG_ARGV instead. CONTEXT: compilation of PL/pgSQL function "test_x" near line 1

回答

0

誤差來自於聲明函數參數在

CREATE OR REPLACE FUNCTION test_x(value integer)

觸發器通常使用包含新的值$ NEW和$ OLD關聯數組或INSERT或UPDATE操作的舊錶格行,或DELETE的空白表格行。

查看完整的示例和說明PL/PGSQL觸發器http://www.postgresql.org/docs/9.3/interactive/pltcl-trigger.html

+0

此代碼我從另一臺服務器獲取數據。首先,我從服務器獲取數據,稍後檢查傳入的數據。如果數據的長度小於5或空值,我想更改新值。我怎樣才能做到這一點? İn這種方式謝謝你的回答。 – SezKo