Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.
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

share|improve this question
    
I think you want the PL/PgSQL EXECUTE command, possibly as EXECUTE ... USING and/or with the format function. Details in the documentation. –  Craig Ringer Mar 27 '13 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. –  GLOIER TECH. Mar 27 '13 at 14:07
    
Er ... do you mean the pre-defined TG_OP variable? –  Craig Ringer Mar 27 '13 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. –  Craig Ringer Mar 27 '13 at 14:30
1  
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. –  dezso Mar 27 '13 at 17:03
show 1 more comment

1 Answer

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.