0
0
PostgreSQLquery~5 mins

RAISE for notices and exceptions in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ANOTICE
BWARNING
CEXCEPTION
DLOG
What does RAISE NOTICE do in a PL/pgSQL block?
AStops execution with an error
BShows an informational message without stopping
CLogs a message to the server log only
DIgnores the message completely
How do you include a variable value in a RAISE message?
AUse % placeholders and pass variables after the message
BUse $variable directly inside the string
CConcatenate strings with +
DVariables cannot be included in RAISE messages
Which RAISE level is best for debugging messages that you want to see only sometimes?
AEXCEPTION
BNOTICE
CWARNING
DDEBUG
What happens if you use RAISE WARNING in a function?
AA warning message is shown but function continues
BFunction stops immediately
CMessage is logged but not shown to user
DNothing happens
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.