Hacker
Hacker

Reputation: 7906

Creating multiple event triggers inside one trigger postgres

I am new to postgres. I want to create a trigger on insert/updated/delete event on a table. I have seen examples showing, trigger created for each event. I was wondering if i can create one trigger for all events together and i know kind of event inside the trigger.

Upvotes: 2

Views: 3304

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 246308

Yes, you can do that.

If you write your trigger in PL/pgSQL, you will have the special variable TG_OP defined. The values are INSERT, UPDATE, DELETE or TRUNCATE, based on what operation caused the trigger to run.

See the documentation for details.

Upvotes: 5

Related Questions