1

I hope that someone can help. Currently I'm working with a PostgreSQL database but I really don't know how I can solve my problem. In PLSQL there are operations inside a trigger called 'INSERTING, UPDATING, DELETING'. But when it comes to PostgreSQL I'm baffered...

In Oracle I can do this:

v_action CHAR(1) := CASE WHEN INSERTING THEN "I" WHEN UPDATING THEN "U" WHEN DELETING THEN "D" END;
1
  • you are looking for TG_OP?.. Commented Dec 5, 2016 at 13:44

1 Answer 1

2

https://www.postgresql.org/docs/current/static/plpgsql-trigger.html

TG_OP Data type text; a string of INSERT, UPDATE, DELETE, or TRUNCATE telling for which operation the trigger was fired.

This should do the trick:

v_action := CASE 
  WHEN TG_OP = 'INSERT' THEN 'I' 
  WHEN TG_OP = 'UPDATE' THEN 'U' 
  WHEN TG_OP = 'DELETE' THEN 'D' 
END;
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, this is what I looked for. But when the trigger gets triggered I get following error: ERROR: column "INSERT" does not exist
What it looks like in my trigger: v_action CHAR(1) := CASE WHEN TG_OP = "INSERT" THEN "I" WHEN TG_OP = "UPDATE" THEN "U" WHEN TG_OP = "DELETE" THEN "D" END;
single quotes, not double.

Your Answer

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.