Bird
0
0

What will be the output of the following PostgreSQL block?

medium📝 query result Q13 of 15
PostgreSQL - Advanced PL/pgSQL
What will be the output of the following PostgreSQL block?
DO $$
BEGIN
  RAISE EXCEPTION 'Error happened';
EXCEPTION
  WHEN OTHERS THEN
    RAISE NOTICE 'Caught an error';
END $$;
AThe block raises an error and stops execution
BIt prints 'Caught an error' as a notice and continues
CIt prints 'Error happened' as a notice
DSyntax error due to missing semicolon
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the RAISE EXCEPTION statement

    The block raises an exception with message 'Error happened'.
  2. Step 2: Check the EXCEPTION block handling

    The exception handler catches all errors (WHEN OTHERS) and raises a NOTICE with 'Caught an error'.
  3. Final Answer:

    It prints 'Caught an error' as a notice and continues -> Option B
  4. Quick Check:

    Exception caught triggers NOTICE message [OK]
Quick Trick: WHEN OTHERS catches all errors and can raise NOTICE [OK]
Common Mistakes:
  • Assuming the error stops execution
  • Confusing EXCEPTION message with NOTICE
  • Thinking syntax error occurs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes