Bird
0
0

Why does this BEFORE INSERT trigger cause an error? CREATE TRIGGER trg BEFORE INSERT ON tbl FOR EACH ROW EXECUTE FUNCTION trg_func();

medium📝 Debug Q7 of 15
PostgreSQL - Triggers in PostgreSQL
Why does this BEFORE INSERT trigger cause an error? CREATE TRIGGER trg BEFORE INSERT ON tbl FOR EACH ROW EXECUTE FUNCTION trg_func();
AThe trigger function trg_func() is missing or not defined
BBEFORE triggers cannot be used on INSERT events
CFOR EACH ROW is invalid syntax for BEFORE triggers
DTrigger name cannot be 'trg'
Step-by-Step Solution
Solution:
  1. Step 1: Validate trigger syntax

    The syntax is correct for a BEFORE INSERT trigger with FOR EACH ROW.
  2. Step 2: Check trigger function existence

    If trg_func() is not created or defined, PostgreSQL raises an error when creating or firing the trigger.
  3. Final Answer:

    The trigger function trg_func() is missing or not defined -> Option A
  4. Quick Check:

    Trigger function must exist before creating trigger [OK]
Quick Trick: Always create trigger function before creating trigger [OK]
Common Mistakes:
  • Assuming BEFORE triggers can't be on INSERT
  • Thinking FOR EACH ROW is invalid here
  • Believing trigger name restrictions cause error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes