Bird
0
0

You wrote this trigger function for DELETE:

medium📝 Debug Q14 of 15
PostgreSQL - Triggers in PostgreSQL
You wrote this trigger function for DELETE:
CREATE FUNCTION trg_delete_check() RETURNS trigger AS $$
BEGIN
  IF NEW.id IS NULL THEN
    RAISE EXCEPTION 'ID cannot be null';
  END IF;
  RETURN OLD;
END;
$$ LANGUAGE plpgsql;

What is the error in this function?
ARAISE EXCEPTION syntax is wrong
BRETURN OLD is invalid in DELETE triggers
CUsing NEW in a DELETE trigger where only OLD is available
DFunction must return VOID, not trigger
Step-by-Step Solution
Solution:
  1. Step 1: Check record variables in DELETE triggers

    In DELETE triggers, the NEW record is not available because no new row is inserted or updated.
  2. Step 2: Identify incorrect usage of NEW

    The function incorrectly uses NEW.id, which causes an error. It should use OLD.id instead.
  3. Final Answer:

    Using NEW in a DELETE trigger where only OLD is available -> Option C
  4. Quick Check:

    DELETE triggers have OLD, not NEW = C [OK]
Quick Trick: Use OLD in DELETE triggers; NEW is unavailable [OK]
Common Mistakes:
  • Using NEW in DELETE triggers
  • Returning OLD incorrectly
  • Misunderstanding trigger return types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes