| Goal | This query identifies row-level BEFORE triggers that invoke a RAISE WARNING or RAISE EXCEPTION statement without any conditional logic—neither in the trigger's WHEN clause nor within the function body. This means that the trigger unconditionally raises the message for every affected row. This anti-pattern either entirely blocks the triggering DML operation (in the case of an error) or floods the database logs (in the case of a warning), which typically indicates left-over debugging code or an incomplete implementation. |
|---|---|
| Type | Problem detection Each row in the result could represent a flaw in the design |
| Reliability | Medium Medium number of false-positive results |
| License | MIT (opens in new tab) |
| Data Source | INFORMATION_SCHEMA+system catalog |
| SQL Query |
|
Fixing Suggestion
To resolve this issue, review the trigger's intended business logic. If the trigger is meant to enforce a specific rule on individual records, wrap the RAISE statement within an IF condition or add a WHEN clause. However, if the actual goal is to completely forbid a specific DML operation (e.g., preventing all UPDATEs on an append-only table), replace the row-level trigger with a statement-level trigger (FOR EACH STATEMENT), as it is significantly more efficient and semantically correct. If the unconditional error was merely leftover debug code, drop the trigger entirely.
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.
| Name | Description |
|---|---|
| Triggers and rules | Queries of this category provide information about triggers and rules in a database. |