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.
#601. NULLS NOT DISTINCT restriction on unique keys on mandatory columns
INFORMATION_SCHEMA+system catalog base tablesThis query identifies unique constraints and indexes configured with the NULLS NOT DISTINCT property where all involved columns are mandatory (NOT NULL). Using this modifier on strictly mandatory columns is completely redundant. Since the columns cannot contain NULL values in the first place, the special null-handling logic serves no purpose and only unnecessarily clutters the database schema.
#602. Number of columns covered with constraints
INFORMATION_SCHEMA+system catalog base tablesFor different types of constraints find the number of columns covered with constraints of such type.
#603. Number of derived tables that aggregate data
INFORMATION_SCHEMA+system catalog base tablesFind the number of derived tables that aggregate data.
#604. Number of rows in base tables
system catalog base tables onlyFind the number of rows in base tables.
#605. Number of system-generated and user-defined constraint names by constraint type (constraints that involve more than one column)
system catalog base tables onlyFind the number of system-generated constraint names by constraint type. Names should follow the same style. If there is a mix of system-generated and user-defined names, then the style is most probably different.
#606. Number of system-generated and user-defined constraint names by constraint type (constraints that involve one column)
system catalog base tables onlyFind the number of system-generated constraint names by constraint type. Names should follow the same style. If there is a mix of system-generated and user-defined names, then the style is most probably different.
#607. Number of tables covered by derived tables
INFORMATION_SCHEMA+system catalog base tablesFind the number of base tables, the number of base tables that are referred from at least one derived table (view or materialized view), the number of base tables that are referred from at least one view, and the number of base tables that are referred from at least one materialized view. If the database is used through the public database interface (virtual data layer), then, ideally, each table is referred from the subquery of at least one derived table.
#608. Number of underlying tables of derived tables
INFORMATION_SCHEMA+system catalog base tablesFind for each view or materialized view the number of tables based on which the derived table has been directly defined. These tables could be base tables or derived tables.
#609. Number of used tables
INFORMATION_SCHEMA+system catalog base tablesFind statistics about how many derived tables have how many different underlying tables.
#610. Number of using views
INFORMATION_SCHEMA+system catalog base tablesFind statistics about how many base tables have how many derived tables that use these tables.
#611. Number of views with and without security barrier
INFORMATION_SCHEMA+system catalog base tablesFind the number of views, the number of views with and without security barrier setting, and the names of views with and without the security barrier setting.
#612. Numeric columns restricting decimal places via CHECK constraints instead of type scale
INFORMATION_SCHEMA+system catalog base tablesThis query identifies numeric columns (including columns typed via a domain over numeric) that use a single-column table or domain CHECK constraint to restrict the number of decimal places (digits after the decimal point), such as CHECK (price = round(price, 2)), CHECK (trunc(price, 2) = price), CHECK (scale(price) <= 2), CHECK (mod(price, 0.01) = 0), or CHECK (price::text ~ '^[0-9]+(\.[0-9]{1,2})?$').
In PostgreSQL, decimal precision and scale are normally declared directly on the data type itself (e.g., NUMERIC(10, 2)). Enforcing scale via a CHECK constraint instead of the type definition hides the scale from database metadata catalogs (such as information_schema.columns.numeric_scale) and ORM/UI tools, while adding unnecessary per-row function evaluation overhead.
Moreover, if the column already specifies a matching scale (e.g., NUMERIC(10, 2), where numeric_scale IS NOT NULL), the CHECK constraint is completely redundant because PostgreSQL automatically rounds input values to the column's declared scale before evaluating CHECK constraints. Note that for an unconstrained NUMERIC column (numeric_scale IS NULL), a CHECK constraint strictly rejects excess decimal digits (e.g., 1.234) with an error, whereas NUMERIC(10, 2) silently rounds them to 1.23; reviewers should verify which behavior is required.
#613. Object identifiers using reserved or partially reserved SQL keywords (aggregate view)
INFORMATION_SCHEMA+system catalog base tablesThis query identifies reserved or partially reserved SQL keywords in PostgreSQL (categories R, T, and C) that are used as object identifiers, presenting an aggregated summary of their occurrence counts. As Robert C. Martin notes in Clean Code: "Names in software are 90 percent of what make software readable. You need to take the time to choose them wisely and keep them relevant. Names are too important to treat carelessly. Names should not cause confusion." In PostgreSQL, "there are several different classes of tokens ranging from those that can never be used as an identifier to those that have absolutely no special status in the parser as compared to an ordinary identifier" (PostgreSQL Documentation). Although PostgreSQL permits these non-unreserved keywords to be used as identifiers—either by enclosing them in double quotes or, for partially reserved categories, using them unquoted only for certain types of database objects—doing so creates several issues:
- Quoting and syntax friction: Reserved keywords often require double-quoting (e.g.,
"user"or"order"), making identifiers case-sensitive, tedious to write, and prone to syntax errors in raw SQL queries and ORMs. - Portability risks: Even when PostgreSQL allows a partially reserved keyword unquoted in a specific context (such as a column or function name), it may be strictly reserved across all contexts in other RDBMS platforms, significantly complicating future database migrations.
- Vague semantics: SQL keywords are typically overly generic and fail to convey clear, specific domain information about the named object.
#614. Object identifiers using reserved or partially reserved SQL keywords (detailed view)
INFORMATION_SCHEMA+system catalog base tablesThis query identifies user-defined database objects whose names (identifiers) match SQL keywords that are reserved or partially reserved in PostgreSQL (categories R, T, and C). As Robert C. Martin notes in Clean Code: "Names in software are 90 percent of what make software readable. You need to take the time to choose them wisely and keep them relevant. Names are too important to treat carelessly. Names should not cause confusion." In PostgreSQL, "there are several different classes of tokens ranging from those that can never be used as an identifier to those that have absolutely no special status in the parser as compared to an ordinary identifier" (PostgreSQL Documentation). Although PostgreSQL permits these keywords to be used as identifiers—either by enclosing them in double quotes or, for partially reserved categories, using them unquoted only for certain types of database objects—doing so creates several issues:
- Quoting and syntax friction: Reserved keywords often require double-quoting (e.g.,
"user"or"order"), making identifiers case-sensitive, tedious to write, and prone to syntax errors in raw SQL queries and ORMs. - Portability risks: Even when PostgreSQL allows a partially reserved keyword unquoted in a specific context (such as a column or function name), it may be strictly reserved across all contexts in other RDBMS platforms, significantly complicating future database migrations.
- Vague semantics: SQL keywords are typically overly generic and fail to convey clear, specific domain information about the named object.
#615. Object identifiers using unreserved SQL keywords (aggregate view)
INFORMATION_SCHEMA+system catalog base tablesThis query identifies completely unreserved SQL keywords in PostgreSQL that are used as object identifiers, presenting an aggregated summary of their occurrence counts. As Robert C. Martin notes in Clean Code: "Names in software are 90 percent of what make software readable. You need to take the time to choose them wisely and keep them relevant. Names are too important to treat carelessly. Names should not cause confusion." In PostgreSQL, "there are several different classes of tokens ranging from those that can never be used as an identifier to those that have absolutely no special status in the parser as compared to an ordinary identifier" (PostgreSQL Documentation). Although PostgreSQL permits unreserved keywords (such as status, type, date, value, key, or comment) to be used freely as unquoted identifiers, doing so creates two issues:
- Portability risks: Words that are unreserved in PostgreSQL may be strictly reserved keywords in other RDBMS platforms, significantly complicating future database migrations.
- Vague semantics: SQL keywords are typically overly generic and fail to convey clear, specific domain information about the named object.
#616. Object identifiers using unreserved SQL keywords (detailed view)
INFORMATION_SCHEMA+system catalog base tablesThis query identifies user-defined database objects whose names (identifiers) match SQL keywords that are completely unreserved in PostgreSQL. As Robert C. Martin notes in Clean Code: 'Names in software are 90 percent of what make software readable. You need to take the time to choose them wisely and keep them relevant. Names are too important to treat carelessly. Names should not cause confusion.' In PostgreSQL, 'there are several different classes of tokens ranging from those that can never be used as an identifier to those that have absolutely no special status in the parser as compared to an ordinary identifier' (PostgreSQL Documentation). Although PostgreSQL permits unreserved keywords (such as status, type, date, value, key, or comment) to be used freely as unquoted identifiers, doing so creates two issues:
- Portability risks: Words that are unreserved in PostgreSQL may be strictly reserved keywords in other RDBMS platforms, significantly complicating future database migrations.
- Vague semantics: SQL keywords are typically overly generic and fail to convey clear, specific domain information about the named object.
#617. ON DELETE CASCADE is not needed (based on classifier tables)
INFORMATION_SCHEMA+system catalog base tablesThis query identifies foreign key constraints with ON DELETE CASCADE that reference classifier tables. Classifier tables hold reference data (e.g., status types, categories), and their rows should not be deleted if they are in use. Applying ON DELETE CASCADE to such a relationship is a critical design flaw, as it creates a direct path for the deletion of a single lookup value to trigger the mass deletion of operational business data.
#618. ON DELETE CASCADE is probably missing (based on the multiplicity of the relationship)
system catalog base tables onlyThis query identifies foreign key constraints that likely require an ON DELETE CASCADE action. It targets a specific pattern: where the foreign key constraint's columns are identical to a candidate key (Primary Key or Unique constraint) of the same table. This structure implements a one-to-one identifying relationship, where the child entity is existentially dependent on the parent (a weak entity depending on a strong entity). The absence of ON DELETE CASCADE in this scenario is a design flaw, as it prevents the parent row from being deleted and breaks the conceptual model.
#619. ON DELETE CASCADE is probably not needed (based on the relationship type)
system catalog base tables onlyThis query identifies foreign key constraints that use ON DELETE CASCADE in a non-identifying relationship. A relationship is considered non-identifying if the foreign key columns in the child table are not part of the child table's candidate key. In such cases, the child entity has its own independent identity, and using ON DELETE CASCADE is often a design flaw that can lead to unexpected and catastrophic data loss.
#620. ON DELETE SET NULL is probably missing
system catalog base tables onlyFind implementations of the adjacency list design pattern, where the corresponding foreign key columns are optional but the foreign key constraint does not have ON DELETE SET NULL compensating action. Implement adjacency list correctly.
| # | 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 |
|---|---|---|---|---|---|---|---|
| 601 | NULLS NOT DISTINCT restriction on unique keys on mandatory columns | This query identifies unique constraints and indexes configured with the NULLS NOT DISTINCT property where all involved columns are mandatory (NOT NULL). Using this modifier on strictly mandatory columns is completely redundant. Since the columns cannot contain NULL values in the first place, the special null-handling logic serves no purpose and only unnecessarily clutters the database schema. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 602 | Number of columns covered with constraints | For different types of constraints find the number of columns covered with constraints of such type. | Sofware measure | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 603 | Number of derived tables that aggregate data | Find the number of derived tables that aggregate data. | Sofware measure | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 604 | Number of rows in base tables | Find the number of rows in base tables. | General | system catalog base tables only | MIT (opens in new tab) | View | |
| 605 | Number of system-generated and user-defined constraint names by constraint type (constraints that involve more than one column) | Find the number of system-generated constraint names by constraint type. Names should follow the same style. If there is a mix of system-generated and user-defined names, then the style is most probably different. | Sofware measure | system catalog base tables only | MIT (opens in new tab) | View | |
| 606 | Number of system-generated and user-defined constraint names by constraint type (constraints that involve one column) | Find the number of system-generated constraint names by constraint type. Names should follow the same style. If there is a mix of system-generated and user-defined names, then the style is most probably different. | Sofware measure | system catalog base tables only | MIT (opens in new tab) | View | |
| 607 | Number of tables covered by derived tables | Find the number of base tables, the number of base tables that are referred from at least one derived table (view or materialized view), the number of base tables that are referred from at least one view, and the number of base tables that are referred from at least one materialized view. If the database is used through the public database interface (virtual data layer), then, ideally, each table is referred from the subquery of at least one derived table. | Sofware measure | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 608 | Number of underlying tables of derived tables | Find for each view or materialized view the number of tables based on which the derived table has been directly defined. These tables could be base tables or derived tables. | Sofware measure | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 609 | Number of used tables | Find statistics about how many derived tables have how many different underlying tables. | Sofware measure | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 610 | Number of using views | Find statistics about how many base tables have how many derived tables that use these tables. | Sofware measure | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 611 | Number of views with and without security barrier | Find the number of views, the number of views with and without security barrier setting, and the names of views with and without the security barrier setting. | Sofware measure | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 612 | Numeric columns restricting decimal places via CHECK constraints instead of type scale | This query identifies numeric columns (including columns typed via a domain over numeric) that use a single-column table or domain CHECK constraint to restrict the number of decimal places (digits after the decimal point), such as CHECK (price = round(price, 2)), CHECK (trunc(price, 2) = price), CHECK (scale(price) <= 2), CHECK (mod(price, 0.01) = 0), or CHECK (price::text ~ '^[0-9]+(\.[0-9]{1,2})?$').In PostgreSQL, decimal precision and scale are normally declared directly on the data type itself (e.g., NUMERIC(10, 2)). Enforcing scale via a CHECK constraint instead of the type definition hides the scale from database metadata catalogs (such as information_schema.columns.numeric_scale) and ORM/UI tools, while adding unnecessary per-row function evaluation overhead.Moreover, if the column already specifies a matching scale (e.g., NUMERIC(10, 2), where numeric_scale IS NOT NULL), the CHECK constraint is completely redundant because PostgreSQL automatically rounds input values to the column's declared scale before evaluating CHECK constraints. Note that for an unconstrained NUMERIC column (numeric_scale IS NULL), a CHECK constraint strictly rejects excess decimal digits (e.g., 1.234) with an error, whereas NUMERIC(10, 2) silently rounds them to 1.23; reviewers should verify which behavior is required. |
Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 613 | Object identifiers using reserved or partially reserved SQL keywords (aggregate view) | This query identifies reserved or partially reserved SQL keywords in PostgreSQL (categories R, T, and C) that are used as object identifiers, presenting an aggregated summary of their occurrence counts. As Robert C. Martin notes in Clean Code: "Names in software are 90 percent of what make software readable. You need to take the time to choose them wisely and keep them relevant. Names are too important to treat carelessly. Names should not cause confusion." In PostgreSQL, "there are several different classes of tokens ranging from those that can never be used as an identifier to those that have absolutely no special status in the parser as compared to an ordinary identifier" (PostgreSQL Documentation). Although PostgreSQL permits these non-unreserved keywords to be used as identifiers—either by enclosing them in double quotes or, for partially reserved categories, using them unquoted only for certain types of database objects—doing so creates several issues:
|
Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 614 | Object identifiers using reserved or partially reserved SQL keywords (detailed view) | This query identifies user-defined database objects whose names (identifiers) match SQL keywords that are reserved or partially reserved in PostgreSQL (categories R, T, and C). As Robert C. Martin notes in Clean Code: "Names in software are 90 percent of what make software readable. You need to take the time to choose them wisely and keep them relevant. Names are too important to treat carelessly. Names should not cause confusion." In PostgreSQL, "there are several different classes of tokens ranging from those that can never be used as an identifier to those that have absolutely no special status in the parser as compared to an ordinary identifier" (PostgreSQL Documentation). Although PostgreSQL permits these keywords to be used as identifiers—either by enclosing them in double quotes or, for partially reserved categories, using them unquoted only for certain types of database objects—doing so creates several issues:
|
Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 615 | Object identifiers using unreserved SQL keywords (aggregate view) | This query identifies completely unreserved SQL keywords in PostgreSQL that are used as object identifiers, presenting an aggregated summary of their occurrence counts. As Robert C. Martin notes in Clean Code: "Names in software are 90 percent of what make software readable. You need to take the time to choose them wisely and keep them relevant. Names are too important to treat carelessly. Names should not cause confusion." In PostgreSQL, "there are several different classes of tokens ranging from those that can never be used as an identifier to those that have absolutely no special status in the parser as compared to an ordinary identifier" (PostgreSQL Documentation). Although PostgreSQL permits unreserved keywords (such as status, type, date, value, key, or comment) to be used freely as unquoted identifiers, doing so creates two issues:
|
Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 616 | Object identifiers using unreserved SQL keywords (detailed view) | This query identifies user-defined database objects whose names (identifiers) match SQL keywords that are completely unreserved in PostgreSQL. As Robert C. Martin notes in Clean Code: 'Names in software are 90 percent of what make software readable. You need to take the time to choose them wisely and keep them relevant. Names are too important to treat carelessly. Names should not cause confusion.' In PostgreSQL, 'there are several different classes of tokens ranging from those that can never be used as an identifier to those that have absolutely no special status in the parser as compared to an ordinary identifier' (PostgreSQL Documentation). Although PostgreSQL permits unreserved keywords (such as status, type, date, value, key, or comment) to be used freely as unquoted identifiers, doing so creates two issues:
|
Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 617 | ON DELETE CASCADE is not needed (based on classifier tables) | This query identifies foreign key constraints with ON DELETE CASCADE that reference classifier tables. Classifier tables hold reference data (e.g., status types, categories), and their rows should not be deleted if they are in use. Applying ON DELETE CASCADE to such a relationship is a critical design flaw, as it creates a direct path for the deletion of a single lookup value to trigger the mass deletion of operational business data. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 618 | ON DELETE CASCADE is probably missing (based on the multiplicity of the relationship) | This query identifies foreign key constraints that likely require an ON DELETE CASCADE action. It targets a specific pattern: where the foreign key constraint's columns are identical to a candidate key (Primary Key or Unique constraint) of the same table. This structure implements a one-to-one identifying relationship, where the child entity is existentially dependent on the parent (a weak entity depending on a strong entity). The absence of ON DELETE CASCADE in this scenario is a design flaw, as it prevents the parent row from being deleted and breaks the conceptual model. | Problem detection | system catalog base tables only | MIT (opens in new tab) | View | |
| 619 | ON DELETE CASCADE is probably not needed (based on the relationship type) | This query identifies foreign key constraints that use ON DELETE CASCADE in a non-identifying relationship. A relationship is considered non-identifying if the foreign key columns in the child table are not part of the child table's candidate key. In such cases, the child entity has its own independent identity, and using ON DELETE CASCADE is often a design flaw that can lead to unexpected and catastrophic data loss. | Problem detection | system catalog base tables only | MIT (opens in new tab) | View | |
| 620 | ON DELETE SET NULL is probably missing | Find implementations of the adjacency list design pattern, where the corresponding foreign key columns are optional but the foreign key constraint does not have ON DELETE SET NULL compensating action. Implement adjacency list correctly. | Problem detection | system catalog base tables only | MIT (opens in new tab) | View |