Verify your knowledge
- What is the
NEW
record?The
NEW
record is the record that is going to be processed before anINSERT
statement or anUPDATE
statement, for example:insert into mytable(id,city_name) values (1,'New York')
NEW.id = 1 NEW.city_name = 'New York'
See the section Exploring rules in PostgreSQL for more details.
- Can we execute an
INSERT
on two tables in a single transaction using rules?Yes, we can; we can make it using the
ALSO
clause. See the section Exploring rules in PostgreSQL for more details.
- Can we make all the things we do with rules using triggers?
Yes, we can; by using triggers, we can make all the things we do with rules and more. See the section Managing triggers in PostgreSQL for more details.
- Can we know if a trigger has been fired from an
INSERT
event, from an updateEVENT
, or from aDELETE
event?Yes, we can, using the
TG_OP
variable...