Bird
0
0

Identify the error in this trigger function:

medium📝 Debug Q6 of 15
PostgreSQL - Triggers in PostgreSQL
Identify the error in this trigger function:
CREATE FUNCTION trg_wrong() RETURNS trigger AS $$ BEGIN PERFORM some_nonexistent_function(); RETURN NEW; END; $$ LANGUAGE plpgsql;
AThe function calls a nonexistent function causing runtime error
BThe function should return void, not trigger
CThe language should be SQL, not plpgsql
DThe function is missing a RETURN statement
Step-by-Step Solution
Solution:
  1. Step 1: Check function calls inside trigger

    The function calls some_nonexistent_function(), which does not exist and causes an error.
  2. Step 2: Verify return type and language

    Return type trigger and language plpgsql are correct for trigger functions.
  3. Final Answer:

    The function calls a nonexistent function causing runtime error -> Option A
  4. Quick Check:

    Calling undefined function = runtime error [OK]
Quick Trick: Ensure all called functions exist in trigger code [OK]
Common Mistakes:
  • Ignoring undefined function calls
  • Confusing return type requirements
  • Changing language unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes