Filter Queries
- All the queries about database objects contain a subcondition to exclude from the result information about the system catalog.
- Although the statements use SQL constructs (common table expressions; NOT in subqueries) that could cause performance problems in case of large datasets, it shouldn't be a problem in case of the relatively small amount of data in the system catalog of a database.
#1041. Updatable views missing WITH CHECK OPTION
INFORMATION_SCHEMA onlyThis query identifies automatically updatable views that lack the WITH CHECK OPTION clause. Without this constraint, it is possible to perform INSERT or UPDATE operations through the view that create rows which do not satisfy the view's defining predicate (the WHERE clause). This results in "phantom" modifications where the new or updated data is successfully committed to the base table but is immediately excluded from the view's result set. Enforcing WITH CHECK OPTION ensures that all data modifications performed through the view remain visible within the view.
#1042. Updatable views that have not been turned to read only
INFORMATION_SCHEMA+system catalog base tablesThis query identifies views that are automatically updatable by the database engine but lack explicit safeguards to prevent data modification. Specifically, it targets views that meet the criteria for auto-updatability (typically simple projections of a single base table) yet are missing an INSTEAD OF trigger or a DO INSTEAD NOTHING rule. Without these mechanisms, any INSERT, UPDATE, or DELETE operation performed against the view will seamlessly propagate to the underlying base table, which may violate the intended read-only design contract.
#1043. Updatable views with WHERE clause that do not have WITH CHECK OPTION constraint
INFORMATION_SCHEMA onlyThis query identifies automatically updatable views that define a row restriction (via a WHERE clause) but lack the WITH CHECK OPTION constraint. In the absence of this constraint, it is possible to perform INSERT or UPDATE operations through the view that result in rows satisfying the base table constraints but failing the view's inclusion criteria. This leads to "phantom updates," where the modified data is committed to the database but immediately disappears from the view's scope. Enforcing WITH CHECK OPTION ensures that all modifications performed through the view respect its defining predicate.
#1044. UPDATE triggers
INFORMATION_SCHEMA onlyFind all UPDATE triggers. Make sure that they specify a correct set of columns in which data modification will fire the trigger.
#1045. UPDATE triggers where updated columns have not been specified (the trigger could executed too often)
INFORMATION_SCHEMA onlyFind UPDATE triggers where updated columns are not specified. These triggers could be executed too often because unneeded executions are not prevented.
#1046. UPDATE triggers where WHEN clause has not been specified (the trigger could executed too often)
INFORMATION_SCHEMA onlyFind UPDATE triggers where WHEN clause is not specified. These triggers could be executed too often because unneeded executions are not prevented.
#1047. Updating or deleting data in a routine without restricting rows
INFORMATION_SCHEMA+system catalog base tablesThis query identifies user-defined routines that contain unbounded Data Modification Language (DML) statements. Specifically, it flags routines containing UPDATE or DELETE operations that lack a qualifying WHERE clause. Such statements result in full-table modifications, affecting every row in the target relation. While valid in specific maintenance contexts, this pattern typically represents a critical logic error in transactional code, posing a severe risk of unintended massive data loss or corruption.
#1048. Usage of base tables
INFORMATION_SCHEMA+system catalog base tablesFind for each derived table the list of base tables that are used by the derived table.
#1049. Usage of the non-standard now() function
INFORMATION_SCHEMA+system catalog base tablesThis query identifies all expressions that use the non-standard now() function. In PostgreSQL, now() is a historical, non-standard alias for the SQL-standard current_timestamp. While they are functionally identical within PostgreSQL (both returning the transaction start timestamp as a TIMESTAMPTZ), the use of current_timestamp is strongly preferred for reasons of code portability and adherence to standards. Standardizing on current_timestamp ensures the code is universally understood and easier to maintain or migrate to other database systems.
#1050. Used indexes
INFORMATION_SCHEMA+system catalog base tablesFind indexes that are used by the DBMS.
#1051. Use invocation of a precise function instead of casting in a default value expression
INFORMATION_SCHEMA onlyBe precise and write as little code as possible. Prefer expressions with simple invocations of functions like localtimestamp, current_timestamp, and current_date over expressions like (now())::date. Find table columns that have a default value that casts the type of the returned value of a non-deterministic function (now, localtimestamp, current_timestamp, and current_date).
#1052. Useless trivial non-trigger functions
INFORMATION_SCHEMA+system catalog base tablesThis query identifies user-defined routines (excluding triggers) that are functionally trivial. It flags routines whose body consists solely of returning a static value: either an input argument (identity function), a constant literal, or NULL. Such routines typically perform no computation, data manipulation, or side effects. They are likely placeholders, deprecated logic, or artifacts of incomplete refactoring, and should be reviewed for removal or implementation.
#1053. Useless trivial trigger functions
INFORMATION_SCHEMA+system catalog base tablesThis query identifies trigger functions that are functionally trivial, specifically those whose sole action is to execute RETURN NEW. In a BEFORE trigger context, this operation simply allows the data modification to proceed unchanged. If the function contains no other logic (e.g., validation, modification of NEW, or side effects), it performs no useful work and incurs unnecessary execution overhead. Such triggers are likely incomplete placeholders or obsolete code that should be removed.
#1054. Useless type indication
INFORMATION_SCHEMA+system catalog base tablesFind columns and parameters where the type of the identifier is perhaps explicitly indicated in the name.
#1055. Useless type indication (2)
INFORMATION_SCHEMA+system catalog base tablesFind columns and parameters where the type of the identifier is perhaps explicitly indicated in the name.
#1056. User-defined composite types
system catalog base tables onlyFind composite types that are created by a user, i.e., the type is not created automatically by the database management system based on a relation.
#1057. User-defined derived tables
INFORMATION_SCHEMA+system catalog base tablesFind user-defined views and materialized views. Pay attention to the outer join operations. One should use these if and only if there is a real need for them. Otherwise they just reduce performance. On the other hand, pay attention that outer join is used where it is logically needed.
#1058. User-defined non-trigger routines without parameters
INFORMATION_SCHEMA+system catalog base tablesFind user-defined non-trigger routines with no parameters.
#1059. User-defined non-trigger SQL and PL/pgSQL routines
INFORMATION_SCHEMA+system catalog base tablesThis query retrieves a comprehensive list of user-defined routines (functions and procedures) written in SQL or PL/pgSQL. It explicitly filters the result set to exclude:
- Trigger functions: Routines intended solely for use in triggers are omitted to focus on callable business logic.
- System schemas: Routines located in system-managed namespaces (e.g., pg_catalog, information_schema) are excluded to isolate user-created code.
- Extension routines.
The result provides an inventory of the application's explicit, callable database logic.
#1060. User-defined routine execution privilege has been granted to PUBLIC
INFORMATION_SCHEMA+system catalog base tablesYou should follow the principle of least privilege and thus not have in your database user-defined routines that execution privilege is granted to PUBLIC, i.e., to all the database users now and in the future. By default, PostgreSQL gives routine execution privileges to PUBLIC.
| # | Name(sorted ascending, activate to sort descending) | Goal(activate to sort ascending) | Type(activate to sort ascending) | Data source(activate to sort ascending) | Last update(activate to sort ascending) | License | Actions |
|---|---|---|---|---|---|---|---|
| 1041 | Updatable views missing WITH CHECK OPTION | This query identifies automatically updatable views that lack the WITH CHECK OPTION clause. Without this constraint, it is possible to perform INSERT or UPDATE operations through the view that create rows which do not satisfy the view's defining predicate (the WHERE clause). This results in "phantom" modifications where the new or updated data is successfully committed to the base table but is immediately excluded from the view's result set. Enforcing WITH CHECK OPTION ensures that all data modifications performed through the view remain visible within the view. | Problem detection | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 1042 | Updatable views that have not been turned to read only | This query identifies views that are automatically updatable by the database engine but lack explicit safeguards to prevent data modification. Specifically, it targets views that meet the criteria for auto-updatability (typically simple projections of a single base table) yet are missing an INSTEAD OF trigger or a DO INSTEAD NOTHING rule. Without these mechanisms, any INSERT, UPDATE, or DELETE operation performed against the view will seamlessly propagate to the underlying base table, which may violate the intended read-only design contract. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 1043 | Updatable views with WHERE clause that do not have WITH CHECK OPTION constraint | This query identifies automatically updatable views that define a row restriction (via a WHERE clause) but lack the WITH CHECK OPTION constraint. In the absence of this constraint, it is possible to perform INSERT or UPDATE operations through the view that result in rows satisfying the base table constraints but failing the view's inclusion criteria. This leads to "phantom updates," where the modified data is committed to the database but immediately disappears from the view's scope. Enforcing WITH CHECK OPTION ensures that all modifications performed through the view respect its defining predicate. | Problem detection | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 1044 | UPDATE triggers | Find all UPDATE triggers. Make sure that they specify a correct set of columns in which data modification will fire the trigger. | General | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 1045 | UPDATE triggers where updated columns have not been specified (the trigger could executed too often) | Find UPDATE triggers where updated columns are not specified. These triggers could be executed too often because unneeded executions are not prevented. | Problem detection | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 1046 | UPDATE triggers where WHEN clause has not been specified (the trigger could executed too often) | Find UPDATE triggers where WHEN clause is not specified. These triggers could be executed too often because unneeded executions are not prevented. | Problem detection | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 1047 | Updating or deleting data in a routine without restricting rows | This query identifies user-defined routines that contain unbounded Data Modification Language (DML) statements. Specifically, it flags routines containing UPDATE or DELETE operations that lack a qualifying WHERE clause. Such statements result in full-table modifications, affecting every row in the target relation. While valid in specific maintenance contexts, this pattern typically represents a critical logic error in transactional code, posing a severe risk of unintended massive data loss or corruption. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 1048 | Usage of base tables | Find for each derived table the list of base tables that are used by the derived table. | General | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 1049 | Usage of the non-standard now() function | This query identifies all expressions that use the non-standard now() function. In PostgreSQL, now() is a historical, non-standard alias for the SQL-standard current_timestamp. While they are functionally identical within PostgreSQL (both returning the transaction start timestamp as a TIMESTAMPTZ), the use of current_timestamp is strongly preferred for reasons of code portability and adherence to standards. Standardizing on current_timestamp ensures the code is universally understood and easier to maintain or migrate to other database systems. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 1050 | Used indexes | Find indexes that are used by the DBMS. | General | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 1051 | Use invocation of a precise function instead of casting in a default value expression | Be precise and write as little code as possible. Prefer expressions with simple invocations of functions like localtimestamp, current_timestamp, and current_date over expressions like (now())::date. Find table columns that have a default value that casts the type of the returned value of a non-deterministic function (now, localtimestamp, current_timestamp, and current_date). | Problem detection | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 1052 | Useless trivial non-trigger functions | This query identifies user-defined routines (excluding triggers) that are functionally trivial. It flags routines whose body consists solely of returning a static value: either an input argument (identity function), a constant literal, or NULL. Such routines typically perform no computation, data manipulation, or side effects. They are likely placeholders, deprecated logic, or artifacts of incomplete refactoring, and should be reviewed for removal or implementation. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 1053 | Useless trivial trigger functions | This query identifies trigger functions that are functionally trivial, specifically those whose sole action is to execute RETURN NEW. In a BEFORE trigger context, this operation simply allows the data modification to proceed unchanged. If the function contains no other logic (e.g., validation, modification of NEW, or side effects), it performs no useful work and incurs unnecessary execution overhead. Such triggers are likely incomplete placeholders or obsolete code that should be removed. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 1054 | Useless type indication | Find columns and parameters where the type of the identifier is perhaps explicitly indicated in the name. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 1055 | Useless type indication (2) | Find columns and parameters where the type of the identifier is perhaps explicitly indicated in the name. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 1056 | User-defined composite types | Find composite types that are created by a user, i.e., the type is not created automatically by the database management system based on a relation. | General | system catalog base tables only | MIT (opens in new tab) | View | |
| 1057 | User-defined derived tables | Find user-defined views and materialized views. Pay attention to the outer join operations. One should use these if and only if there is a real need for them. Otherwise they just reduce performance. On the other hand, pay attention that outer join is used where it is logically needed. | General | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 1058 | User-defined non-trigger routines without parameters | Find user-defined non-trigger routines with no parameters. | General | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 1059 | User-defined non-trigger SQL and PL/pgSQL routines | This query retrieves a comprehensive list of user-defined routines (functions and procedures) written in SQL or PL/pgSQL. It explicitly filters the result set to exclude:
The result provides an inventory of the application's explicit, callable database logic. |
General | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 1060 | User-defined routine execution privilege has been granted to PUBLIC | You should follow the principle of least privilege and thus not have in your database user-defined routines that execution privilege is granted to PUBLIC, i.e., to all the database users now and in the future. By default, PostgreSQL gives routine execution privileges to PUBLIC. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View |