Bird
0
0

You wrote this trigger function:

medium📝 Debug Q14 of 15
PostgreSQL - Triggers in PostgreSQL
You wrote this trigger function:
CREATE FUNCTION validate_age() RETURNS trigger AS $$ BEGIN IF NEW.age < 18 THEN RAISE EXCEPTION 'Age must be 18 or older'; END IF; RETURN NEW; END; $$ LANGUAGE plpgsql;
But when inserting age = 15, no error occurs. What is the likely mistake?
ARAISE EXCEPTION syntax is incorrect
BThe trigger is not attached to the table
CThe function does not return NEW
DThe trigger function is missing LANGUAGE plpgsql
Step-by-Step Solution
Solution:
  1. Step 1: Check function correctness

    The function correctly raises exception and returns NEW, syntax is fine.
  2. Step 2: Consider trigger attachment

    If no error occurs, likely the trigger is not linked to the table to run the function.
  3. Final Answer:

    The trigger is not attached to the table -> Option B
  4. Quick Check:

    Trigger must be attached to run function [OK]
Quick Trick: Attach trigger to table to activate validation [OK]
Common Mistakes:
  • Forgetting to create the trigger after function
  • Assuming function runs without trigger
  • Misreading RAISE EXCEPTION syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes