PostgreSQL - Triggers in PostgreSQLWhy must a PostgreSQL trigger function always return either NEW or OLD row?ABecause the trigger mechanism expects a row to continue or cancel the operationBBecause returning void causes the trigger to run twiceCBecause returning NULL automatically commits the transactionDBecause returning NEW or OLD triggers a database restartCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand trigger function return roleTrigger functions return NEW or OLD to tell PostgreSQL what row to use after the trigger runs.Step 2: Explain consequencesReturning NEW continues with the modified row; returning OLD can cancel changes. Returning NULL skips the operation.Final Answer:Because the trigger mechanism expects a row to continue or cancel the operation -> Option AQuick 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 commitBelieving void return triggers restartConfusing NULL return effect
Master "Triggers in PostgreSQL" in PostgreSQL9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PostgreSQL Quizzes Advanced Features - Domain types for validation - Quiz 11easy Indexing Strategies - Hash index for equality - Quiz 14medium PL/pgSQL Fundamentals - Function creation syntax - Quiz 8hard PL/pgSQL Fundamentals - DO blocks for anonymous code - Quiz 13medium Performance Tuning - Why performance tuning matters - Quiz 11easy Roles and Security - Schema-level access control - Quiz 1easy Roles and Security - Row-level security policies - Quiz 2easy Transactions and Concurrency - VACUUM and its importance - Quiz 7medium Transactions and Concurrency - Serializable isolation - Quiz 12easy Triggers in PostgreSQL - NEW and OLD record access - Quiz 2easy