Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to create trigger without execute procedure in postgresql?

i want to create procedure with BL in its body. i find the same example in SQL but not in postgresql.

like image 573
user3555572 Avatar asked Jan 26 '15 11:01

user3555572


People also ask

Does trigger run automatically?

A trigger is a special type of stored procedure that automatically runs when an event occurs in the database server. DML triggers run when a user tries to modify data through a data manipulation language (DML) event.

How do I create a trigger in PostgreSQL?

Syntax. CREATE TRIGGER trigger_name [BEFORE|AFTER|INSTEAD OF] event_name ON table_name [ -- Trigger logic goes here.... ]; Here, event_name could be INSERT, DELETE, UPDATE, and TRUNCATE database operation on the mentioned table table_name. You can optionally specify FOR EACH ROW after table name.

What is instead of trigger in PostgreSQL?

INSTEAD OF triggers do not support WHEN conditions. Typically, row-level BEFORE triggers are used for checking or modifying the data that will be inserted or updated. For example, a BEFORE trigger might be used to insert the current time into a timestamp column, or to check that two elements of the row are consistent.

Can we create trigger in procedure?

The trigger will fire once per statement, so if your INSERT that causes this trigger to fire inserts 25 rows, you'll get the trigger fired once and the Inserted pseudo table will contain 25 rows.


1 Answers

Every RDBMS have their own SQL language. You can't create trigger in PostgreSQL as you can create in Oracle/MS SQL etc. In order to create trigger in PostgreSQL you have to

  1. Create a function in PostgreSQL with you BL
  2. Create a trigger and associate your function with this trigger.
like image 116
M Faisal Hameed Avatar answered Oct 23 '22 18:10

M Faisal Hameed