Recall & Review
beginner
What does the RAISE statement do in PostgreSQL?
The RAISE statement sends messages or errors during the execution of a PL/pgSQL block. It can show notices, warnings, or raise exceptions to stop execution.
Click to reveal answer
beginner
What are the different levels you can use with RAISE in PostgreSQL?
You can use RAISE with levels: NOTICE, WARNING, EXCEPTION, LOG, and DEBUG. EXCEPTION stops execution, others just show messages.
Click to reveal answer
beginner
How do you raise a custom exception with a message in PostgreSQL?
Use: RAISE EXCEPTION 'Your message here'; This stops the function and shows the error message.
Click to reveal answer
beginner
What is the purpose of RAISE NOTICE in a PL/pgSQL function?
RAISE NOTICE shows an informational message to the user without stopping the function. It's useful for debugging or status updates.
Click to reveal answer
intermediate
Can you include variables in RAISE messages? How?
Yes, use format strings with % placeholders and provide variables after the message. Example: RAISE NOTICE 'Value is %', my_var;
Click to reveal answer
Which RAISE level in PostgreSQL stops the execution of a function?
✗ Incorrect
RAISE EXCEPTION stops the function execution and raises an error.
What does RAISE NOTICE do in a PL/pgSQL block?
✗ Incorrect
RAISE NOTICE displays a message to the client but does not stop execution.
How do you include a variable value in a RAISE message?
✗ Incorrect
RAISE supports format strings with % placeholders and variables passed after the message.
Which RAISE level is best for debugging messages that you want to see only sometimes?
✗ Incorrect
RAISE DEBUG is used for detailed debugging messages, which can be enabled or disabled.
What happens if you use RAISE WARNING in a function?
✗ Incorrect
RAISE WARNING shows a warning message but does not stop the function execution.
Explain how to use the RAISE statement to show a notice and to raise an exception in PostgreSQL.
Think about messages that inform vs. errors that stop.
You got /3 concepts.
Describe how to include variable values inside RAISE messages in PL/pgSQL.
It's similar to formatting strings in many programming languages.
You got /3 concepts.