Session Ready
Exercise

Getting stacked diagnostics

Stacked diagnostics can get the internal PostgreSQL error message and exception details. Let's revisit our patients table and try to add an A1C that is above the testing limit. This will cause a check constraint exception that we can capture. We can use the stacked diagnostics in the exception handler to enrich our error recording.

Instructions
100 XP
  • DECLARE two variables exc_message and exc_detail as text.
  • Get the diagnostics stack and set exc_message to be the MESSAGE_TEXT and exc_detail to be the PG_EXCEPTION_DETAIL.
  • Insert exc_message and exc_detail into the msg and detail field of the errors table.