1
CREATE TRIGGER audit_proc_tr
 AFTER INSERT OR UPDATE OR DELETE
 ON "log".hi
 FOR EACH ROW
 EXECUTE PROCEDURE "log".audit_proc(argument);
CREATE OR REPLACE FUNCTION fn_configpurchaseorder(configpurchaseorder, xmode text, xuserno integer)
 RETURNS text AS
 END;

I want to pass xmode is a argument of trigger

asked Mar 27, 2013 at 12:10
6
  • I think you want the PL/PgSQL EXECUTE command, possibly as EXECUTE ... USING and/or with the format function. Details in the documentation. Commented Mar 27, 2013 at 12:38
  • @CraigRinger I think you wrongly understood the question. i want to pass that xMode in the trigger. For example, the function fn_configpurchaseorder(...,xmode text,...) will be called when ever i will do insert/delete/update, that xmode is just to identify about the process(insert/update/delete) that is going to occur. so assume if the fn_configpurchaseorder was called with xMode 'I', if so i will identify, 'oh this call is for insert', similarly after the table gets affected(ins/del/upd) the corresponding trigger will gets called,so in that trigger fn i need to identify the xMode to proceed. Commented Mar 27, 2013 at 14:07
  • Er ... do you mean the pre-defined TG_OP variable? Commented Mar 27, 2013 at 14:14
  • 4
    Couldn't guess what you're really trying to do from this amount of info then. I'd advise you to elaborate. Commented Mar 27, 2013 at 14:30
  • 2
    You can pass arguments to a trigger, but they are string literals, and since they can only be defined at trigger creation, they can be thought as constants. With these you can modify the trigger behaviour if you use the same procedure with multiple triggers, but (AFAIK) can't achieve anything which you can't achieve by using TG_OP, TG_TABLE_NAME and other variables. Commented Mar 27, 2013 at 17:03

1 Answer 1

2

If you want to pass data to a trigger that is not provided by one of the predefined variables you could put that data in a temp table before you perform the INSERT/UPDATE/DELETE that will fire the trigger. Then you can retrieve the data from the table inside the trigger function. Temp tables are local to sessions so this is safe to do when multiple clients connect to the same database.

answered Apr 1, 2013 at 7:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.