Bird
0
0

Why must a PostgreSQL trigger function always return either NEW or OLD row?

hard📝 Conceptual Q10 of 15
PostgreSQL - Triggers in PostgreSQL
Why must a PostgreSQL trigger function always return either NEW or OLD row?
ABecause the trigger mechanism expects a row to continue or cancel the operation
BBecause returning void causes the trigger to run twice
CBecause returning NULL automatically commits the transaction
DBecause returning NEW or OLD triggers a database restart
Step-by-Step Solution
Solution:
  1. Step 1: Understand trigger function return role

    Trigger functions return NEW or OLD to tell PostgreSQL what row to use after the trigger runs.
  2. Step 2: Explain consequences

    Returning NEW continues with the modified row; returning OLD can cancel changes. Returning NULL skips the operation.
  3. Final Answer:

    Because the trigger mechanism expects a row to continue or cancel the operation -> Option A
  4. Quick Check:

    Trigger return value controls row operation continuation [OK]
Quick Trick: Return NEW or OLD to control row operation in triggers [OK]
Common Mistakes:
  • Thinking return value affects transaction commit
  • Believing void return triggers restart
  • Confusing NULL return effect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes