| Goal | This query identifies user-defined routines with an SQL-standard body (BEGIN ATOMIC ... END) that execute an UPDATE statement on a base table containing a modification timestamp or date column, where neither the routine itself nor any row-level BEFORE UPDATE trigger on the target table updates that modification time column. Failing to maintain the modification timestamp during row updates compromises audit trails, data lineage tracking, and synchronization or caching mechanisms that depend on accurate last-modified timestamps. |
|---|---|
| Notes | Queries information_schema.routine_column_usage (which records table and column dependencies for routines written using the SQL-standard BEGIN ATOMIC body introduced in PostgreSQL 14), information_schema.columns, information_schema.routines, and PostgreSQL system catalogs (pg_trigger, pg_proc, pg_class, pg_namespace).
|
| 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
Update the modification time column explicitly in the routine's
UPDATE ... SET clause (for example, SET viimase_muutm_aeg = CURRENT_TIMESTAMP(0) or statement_timestamp()), or create a row-level BEFORE UPDATE trigger on the target table that automatically updates the modification timestamp (NEW.<modification_time_column> := CURRENT_TIMESTAMP(0);) whenever a row is modified. 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:
Result quality depends on names
Queries of this category use names (for instance, column names) to try to guess the meaning of a database object. Thus, the goodness of names determines the number of false positive and false negative results.
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 |
|---|---|
| Result quality depends on names | Queries of this category use names (for instance, column names) to try to guess the meaning of a database object. Thus, the goodness of names determines the number of false positive and false negative results. |
| 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 |