Bird
0
0

You created this trigger but it does not run when you insert data:

medium📝 Debug Q14 of 15
PostgreSQL - Triggers in PostgreSQL
You created this trigger but it does not run when you insert data:
CREATE TRIGGER log_insert AFTER INSERT ON sales EXECUTE FUNCTION log_sale();

What is the likely problem?
AAFTER INSERT triggers cannot be created
BTrigger function name is incorrect
CMissing FOR EACH ROW clause in trigger definition
Dlog_sale() function must return void
Step-by-Step Solution
Solution:
  1. Step 1: Check trigger syntax requirements

    PostgreSQL requires FOR EACH ROW or FOR EACH STATEMENT clause in CREATE TRIGGER statement.
  2. Step 2: Identify missing clause in given trigger

    The trigger lacks FOR EACH ROW or FOR EACH STATEMENT, so it is invalid and will not run.
  3. Final Answer:

    Missing FOR EACH ROW clause in trigger definition -> Option C
  4. Quick Check:

    Triggers need FOR EACH ROW/STATEMENT clause [OK]
Quick Trick: Always include FOR EACH ROW or STATEMENT [OK]
Common Mistakes:
  • Assuming AFTER INSERT triggers are disallowed
  • Thinking function name causes trigger failure
  • Believing trigger functions must return void

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes