Bird
0
0

Find the error in this PL/pgSQL function:

medium📝 Debug Q7 of 15
PostgreSQL - Advanced PL/pgSQL
Find the error in this PL/pgSQL function:
CREATE FUNCTION faulty_func() RETURNS VOID AS $$
BEGIN
  PERFORM SELECT 1 / 0;
END;
$$ LANGUAGE plpgsql;
APERFORM cannot be used in functions
BMissing RETURN statement
CIncorrect function language declaration
DDivision by zero error at runtime
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the PERFORM statement

    PERFORM executes a query but here it attempts division by zero, which causes runtime error.
  2. Step 2: Check other syntax

    RETURN is not needed for VOID functions; language declaration and PERFORM usage are correct.
  3. Final Answer:

    Division by zero error at runtime -> Option D
  4. Quick Check:

    Runtime errors occur on invalid operations like division by zero [OK]
Quick Trick: Watch for runtime errors like division by zero [OK]
Common Mistakes:
  • Expecting missing RETURN error for VOID
  • Thinking PERFORM is invalid
  • Ignoring runtime errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes