| Goal | This query identifies PL/pgSQL routines that invoke RAISE EXCEPTION but fail to include dynamic values (such as the problematic data itself) in the DETAIL clause. Providing only static text in error details is an anti-pattern, as it makes debugging significantly harder. Developers and client applications need to see the actual rejected values to quickly understand and fix the underlying issue. |
|---|---|
| Type | Problem detection Each row in the result could represent a flaw in the design |
| Reliability | High Few or no false-positive results |
| License | MIT (opens in new tab) |
| Data Source | INFORMATION_SCHEMA+system catalog |
| SQL Query |
|
Fixing Suggestion
To resolve this issue, update the RAISE EXCEPTION statement to include the actual data that caused the failure within the DETAIL clause. Use string concatenation or formatting to inject dynamic variables (such as NEW.column_name in case of a trigger routine). For example, instead of a static message, use: USING DETAIL = format('Problematic value provided: %s' , NEW.column_name). This provides actionable, context-rich feedback for troubleshooting
Collections
This query belongs to the following collections:
Find problems automatically
Queries, that results point to problems in the database. Each query in the collection produces an initial assessment. However, a human reviewer has the final say as to whether there is a problem or not .
| Name | Description |
|---|---|
| Find problems automatically | Queries, that results point to problems in the database. Each query in the collection produces an initial assessment. However, a human reviewer has the final say as to whether there is a problem or not . |
Categories
This query is classified under the following categories:
Triggers and rules
Queries of this category provide information about triggers and rules in a database.
User-defined routines
Queries of this category provide information about the user-defined routines
| Name | Description |
|---|---|
| Triggers and rules | Queries of this category provide information about triggers and rules in a database. |
| User-defined routines | Queries of this category provide information about the user-defined routines |