Complete the code to start a block for exception handling in PostgreSQL.
BEGIN[1]The BEGIN keyword starts a block where you can write SQL statements and handle exceptions.
Complete the code to catch exceptions in a PostgreSQL block.
BEGIN -- some code [1] WHEN others THEN RAISE NOTICE 'Error occurred'; END;
The EXCEPTION keyword starts the exception handling section inside a block.
Fix the error in the exception block keyword.
BEGIN -- some code [1] WHEN division_by_zero THEN RAISE NOTICE 'Cannot divide by zero'; END;
The correct keyword to start exception handling in PostgreSQL is EXCEPTION. Other keywords like EXCEPT, CATCH, or HANDLE are not valid here.
Fill both blanks to complete the exception block that handles a unique violation error.
BEGIN INSERT INTO users(username) VALUES('admin'); [1] WHEN unique_violation THEN RAISE NOTICE 'Username already exists'; [2] END;
The EXCEPTION keyword starts the exception handling section, and END closes the block.
Fill all three blanks to complete the exception block that handles division by zero and others.
BEGIN PERFORM 10 / [1]; [2] WHEN division_by_zero THEN RAISE NOTICE 'Division by zero error'; WHEN others THEN RAISE NOTICE 'Some other error'; [3] END;
The first blank is the divisor which causes the error (0). The second blank starts the exception block, and the third blank ends the block.