Friday , June 21 2024

PostgreSQL TRIGGER

In today’s article, we will learn A PostgreSQL trigger is a database object that automatically executes a function in response to an event such as insert, update, delete, or truncate.

Triggers cannot be operated manually by users.

Triggers perform actions before or after the action is taken, according to the actions written in them.

Triggers cause performance loss in DML operations coming to the table in which they are located.

Triggers can cause locks on large data.

After Trigger: Triggers that come into play after the transaction takes place.

Before Trigger: It is the trigger that comes into play after the transaction takes place.

Instead Of Trigger: Used while the action is about to take place.

FOR EACH ROW: It is done for every transaction made. For example, if 1000 deletes were made, it writes them all.

FOR EACH STATEMENT: Performs a single transaction for each transaction made. For example, if 1000 deletes are made, only one will be written.

To define a trigger in PostgreSQL, we first need to create a function or procedure for the desired operation. After doing this, we need to specify the function or procedure created in the trigger.

Its general usage is as follows.

Loading

About Faruk Erdem

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories