PostgreSQL - Triggers in PostgreSQLWhat will be the result of a BEFORE UPDATE trigger that sets NEW.updated_at = NOW() on a row update?AThe updated_at column remains unchangedBThe updated_at column is set to the current timestampCThe update fails with an errorDThe updated_at column is set to NULLCheck Answer
Step-by-Step SolutionSolution:Step 1: Analyze BEFORE UPDATE trigger behaviorThe trigger modifies the NEW row before the update is applied.Step 2: Setting NEW.updated_at = NOW()This sets the updated_at column to the current timestamp at update time.Final Answer:The updated_at column is set to the current timestamp -> Option BQuick Check:BEFORE UPDATE triggers can set timestamp columns [OK]Quick Trick: Use BEFORE UPDATE to set timestamps automatically [OK]Common Mistakes:Assuming updated_at does not changeExpecting an error on updateThinking updated_at becomes NULL
Master "Triggers in PostgreSQL" in PostgreSQL9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PostgreSQL Quizzes Advanced Features - Extensions (pg_trgm, uuid-ossp, hstore) - Quiz 14medium Advanced PL/pgSQL - Functions returning SETOF - Quiz 9hard Advanced PL/pgSQL - Functions returning TABLE - Quiz 8hard Indexing Strategies - Partial indexes with WHERE clause - Quiz 1easy Indexing Strategies - B-tree index (default) behavior - Quiz 10hard PL/pgSQL Fundamentals - DO blocks for anonymous code - Quiz 13medium Roles and Security - Role creation and management - Quiz 9hard Table Partitioning - List partitioning by category - Quiz 2easy Transactions and Concurrency - MVCC mental model in PostgreSQL - Quiz 9hard Transactions and Concurrency - Deadlock detection and prevention - Quiz 2easy