| Goal | This query identifies row-level BEFORE INSERT and BEFORE UPDATE triggers whose primary purpose is not to raise an exception, but which never reference the NEW record outside of the RETURN clause. In PostgreSQL, BEFORE triggers are specifically intended either to validate incoming data (raising exceptions upon failure) or to manipulate column values by modifying NEW. If a trigger does neither, it typically indicates that its logic (such as logging or updating related tables) should be relocated to an AFTER trigger, or that the trigger contains obsolete, redundant code. |
|---|---|
| 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
Refactor the trigger timing from BEFORE to AFTER if it performs side-effect operations (like auditing), or drop the trigger entirely if it no longer serves an active purpose.
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. |
Further reading and related materials: