0
0
PostgreSQLquery~20 mins

RAISE for notices and exceptions in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
RAISE Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this RAISE NOTICE statement?
Consider the following PostgreSQL code snippet:

DO $$ BEGIN RAISE NOTICE 'Hello, %!', 'world'; END $$;

What will be the output when this code runs?
PostgreSQL
DO $$ BEGIN RAISE NOTICE 'Hello, %!', 'world'; END $$;
AAn error is raised and the transaction is aborted
BNo output is shown; the statement runs silently
CA warning message is displayed instead of a notice
DA notice message: "Hello, world!" is displayed
Attempts:
2 left
💡 Hint
RAISE NOTICE is used to send informational messages without stopping execution.
query_result
intermediate
2:00remaining
What error does this RAISE EXCEPTION produce?
Examine this PostgreSQL code:

DO $$ BEGIN RAISE EXCEPTION 'Invalid input: %', 42; END $$;

What happens when this code runs?
PostgreSQL
DO $$ BEGIN RAISE EXCEPTION 'Invalid input: %', 42; END $$;
ANo output; the code runs successfully
BA notice message with text: "Invalid input: 42"
CA runtime error with message: "Invalid input: 42" and transaction abort
DA syntax error due to incorrect RAISE syntax
Attempts:
2 left
💡 Hint
RAISE EXCEPTION stops execution and raises an error.
📝 Syntax
advanced
2:00remaining
Which option causes a syntax error in RAISE statement?
Identify which RAISE statement is syntactically incorrect in PostgreSQL:
ARAISE EXCEPTION 'Error: %' val;
BRAISE WARNING 'Warning: %', val;
CRAISE NOTICE 'Value is %', val;
DRAISE INFO 'Info message';
Attempts:
2 left
💡 Hint
Check the placement of commas and parameters in RAISE syntax.
🧠 Conceptual
advanced
2:00remaining
What is the effect of RAISE EXCEPTION inside a transaction block?
If a RAISE EXCEPTION is executed inside a transaction block in PostgreSQL, what happens?
AThe exception is ignored if inside a transaction
BThe current transaction is aborted and rolled back
CA warning is issued but transaction continues
DOnly the current statement is skipped, transaction continues
Attempts:
2 left
💡 Hint
Think about how exceptions affect transactions in databases.
🔧 Debug
expert
3:00remaining
Why does this RAISE NOTICE not display the variable value?
Given this PostgreSQL code:

DO $$ DECLARE val integer := 10; BEGIN RAISE NOTICE 'Value is %'; END $$;

Why does it not show the value of 'val' in the notice?
PostgreSQL
DO $$ DECLARE val integer := 10; BEGIN RAISE NOTICE 'Value is %'; END $$;
AThe variable 'val' is not passed as an argument to RAISE NOTICE
BThe variable 'val' is out of scope inside the block
CRAISE NOTICE cannot display variables
DThe percent sign '%' is not allowed in RAISE NOTICE
Attempts:
2 left
💡 Hint
Check how placeholders and variables are used in RAISE statements.