Bird
0
0

Why is it important that a PostgreSQL trigger function for data validation returns NEW when used in a BEFORE INSERT or UPDATE trigger?

hard📝 Conceptual Q10 of 15
PostgreSQL - Triggers in PostgreSQL
Why is it important that a PostgreSQL trigger function for data validation returns NEW when used in a BEFORE INSERT or UPDATE trigger?
AReturning NEW allows the modified row to be saved; returning NULL cancels the operation
BReturning NEW causes the trigger to run again recursively
CReturning NULL inserts a default row instead
DReturning OLD updates the existing row with old data
Step-by-Step Solution
Solution:
  1. Step 1: Understand trigger return values

    In BEFORE triggers, returning NEW saves the row with possible changes.
  2. Step 2: Effect of returning NULL

    Returning NULL cancels the insert or update operation.
  3. Final Answer:

    Returning NEW allows the modified row to be saved; returning NULL cancels the operation -> Option A
  4. Quick Check:

    Return NEW to save row, NULL to cancel [OK]
Quick Trick: Return NEW to save changes, NULL to cancel insert/update [OK]
Common Mistakes:
  • Thinking returning NULL saves row
  • Confusing OLD with NEW
  • Assuming recursive trigger calls

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes