Bird
0
0

In a BEFORE UPDATE trigger, what does the following PL/pgSQL statement evaluate to?

medium📝 query result Q4 of 15
PostgreSQL - Triggers in PostgreSQL
In a BEFORE UPDATE trigger, what does the following PL/pgSQL statement evaluate to?
RETURN NEW.price > OLD.price;
ACauses a syntax error
BReturns the new price value
CReturns the old price value
DReturns TRUE if the new price is greater than the old price
Step-by-Step Solution
Solution:
  1. Step 1: Understand the RETURN statement

    The statement returns a boolean result of the comparison between NEW.price and OLD.price.
  2. Step 2: Evaluate the expression

    NEW.price > OLD.price returns TRUE if the new price is greater than the old price, otherwise FALSE.
  3. Final Answer:

    Returns TRUE if the new price is greater than the old price -> Option D
  4. Quick Check:

    Boolean comparison returns TRUE/FALSE [OK]
Quick Trick: RETURN with comparison returns boolean result [OK]
Common Mistakes:
  • Assuming RETURN returns a record instead of boolean
  • Confusing NEW and OLD record references
  • Thinking it causes an error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes