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.
#841. SET NULL compensatory action is unsuitable
INFORMATION_SCHEMA+system catalog base tablesFind foreign key constraints that use a SET NULL compensating action but a foreign key column is mandatory, i.e., does not permit NULLs. Compensatory actions cannot make changes that violate integrity constraints in a database. SET NULL cannot put NULL to a mandatory column (delete a foreign key value).
#842. Set operations that do not remove duplicate rows in derived tables
INFORMATION_SCHEMA+system catalog base tablesFind derived tables (views and materialized views) that use a set theoretic operation (union, except or intersect) in a manner that does not remove duplicate rows and thus can produce a multiset not a set. Make sure that it is what is needed.
#843. Short cycle (columns)
system catalog base tables onlyFind cases where two candidate keys of the same table that are also foreign keys reference to each other.
#844. Short cycles (tables)
INFORMATION_SCHEMA+system catalog base tablesFind pairs of tables that have both a mandatory (NOT NULL) and not defrerrable foreign key that references to the other table. Such cycles can involve more than two tables but the query detects only cycles with two tables.
#845. Should the time zone be recorded in case of time or not?
INFORMATION_SCHEMA onlyFind all the base table columns that have the type time without time zone or time with time zone. Return the data only if there is at least one column with the type time without time zone and one column with the type time with time zone.
#846. Should the time zone be recorded in case of timestamp or not?
INFORMATION_SCHEMA onlyFind all the base table columns that have the type timestamp without time zone or timestamp with time zone. Return the data only if there is at least one column with the type timestamp without time zone and one column with the type timestamp with time zone.
#847. Simple check constraints with multiple tasks
system catalog base tables onlyFind simple check constraints, i.e., check constraints that cover one column that seem to have multiple tasks. The corresponding code smell in case of cleaning code is "G30: Functions Should Do One Thing". (Robert C. Martin, Clean Code)
#848. Simple primary keys that column name does not contain the table name
system catalog base tables onlyFind simple primary keys that column name does not contain the table name. The naming should be clear and consistent.
#849. Simplify regex by combining alpha and digit classes
INFORMATION_SCHEMA+system catalog base tablesThis query identifies regular expressions that can be simplified by consolidating separate character class references. It specifically targets patterns that explicitly match both alphabetic characters ([:alpha:]) and numeric digits ([:digit:], \d, or [0-9]) as separate components within a larger character set (e.g., [[:alpha:][:digit:]]). These distinct classes can be refactored into the single, more concise POSIX character class [:alnum:], which logically represents the union of both. Performing this simplification improves the readability and compactness of the regular expression without altering its behavior.
#850. Single-column natural primary keys
INFORMATION_SCHEMA+system catalog base tablesThis query identifies primary keys that consist of a single column and are not system-generated (i.e., they are not associated with a sequence or defined as IDENTITY columns). This pattern is characteristic of a natural primary key, where the key's value is derived from a real-world, user-defined attribute rather than an arbitrary surrogate value. Identifying these keys is crucial for auditing a data model's key strategy and understanding its reliance on meaningful, potentially mutable, business data for entity identification.
#851. Small tables
INFORMATION_SCHEMA+system catalog base tablesFind tables that have one column or zero columns.
#852. Snake_case violations detected by common suffixes
INFORMATION_SCHEMA+system catalog base tablesThis query identifies database identifiers (columns, parameters, etc.) that likely violate the snake_case naming convention based on suffix analysis. It flags names ending with common temporal or attributional terms (date, time, by) where the suffix is not immediately preceded by an underscore. This pattern is highly indicative of camelCase (e.g., createdDate, updatedBy) or PascalCase usage. Adhering to snake_case (e.g., created_date, updated_by) is the recommended standard for SQL database schemas to ensure consistency and readability.
#853. Some candidate key values cannot be used as foreign key values
INFORMATION_SCHEMA+system catalog base tablesFind foreign key constraints in case of which some candidate key values cannot be used as foreign key values. Primary key/unique columns and foreign key columns should have the same data type and field size. If, for instance, the primary key column has type INTEGER and foreign key column has type SMALLINT, then one cannot use all the primary key values as foreign key values.
#854. Some CHECKS are associated with a domain and some with the base table columns that have the domain
INFORMATION_SCHEMA+system catalog base tablesFind cases where some CHECKS are associated with a domain and some with the base table columns that have the domain. Avoid duplication of code. Write as little code as possible. If possible, move things "before the brackets" so to say. In this case it means declaring CHECKS at the level of the domain and not at the level of base table columns.
#855. Some data modification functions return a value and some not
INFORMATION_SCHEMA+system catalog base tablesFind as to whether there are data modification routines that return a value as well as data modification routines that do not return a value.
#856. Something is still to do in routines
INFORMATION_SCHEMA+system catalog base tablesFind routines where comments contain TODO phrase.
#857. Sometimes current_timestamp, sometimes now()
INFORMATION_SCHEMA+system catalog base tablesFind as to whether you sometimes use current_timestamp function and sometimes now() function. These implement the same functionality.
#858. Sometimes extract, sometimes date_part
INFORMATION_SCHEMA+system catalog base tablesFind as to whether you sometimes use date_part function and sometimes extract function. These implement the same functionality.
#859. Sometimes regexp_like, sometimes ~
INFORMATION_SCHEMA+system catalog base tablesFind as to whether you sometimes use regexp_like function and sometimes ~ operator. These implement the same functionality. regexp_like function that was added to PostgreSQL 15 and provides the same functionality as ~ and ~* operators. Try to be consistent.
#860. Sorting rows based on random values in derived tables
INFORMATION_SCHEMA+system catalog base tablesFind derived tables (views and materialized views) that sort rows based on random values. This can be used to find a random subset of rows. It is a computationally expensive operation.
| # | 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 |
|---|---|---|---|---|---|---|---|
| 841 | SET NULL compensatory action is unsuitable | Find foreign key constraints that use a SET NULL compensating action but a foreign key column is mandatory, i.e., does not permit NULLs. Compensatory actions cannot make changes that violate integrity constraints in a database. SET NULL cannot put NULL to a mandatory column (delete a foreign key value). | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 842 | Set operations that do not remove duplicate rows in derived tables | Find derived tables (views and materialized views) that use a set theoretic operation (union, except or intersect) in a manner that does not remove duplicate rows and thus can produce a multiset not a set. Make sure that it is what is needed. | General | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 843 | Short cycle (columns) | Find cases where two candidate keys of the same table that are also foreign keys reference to each other. | Problem detection | system catalog base tables only | MIT (opens in new tab) | View | |
| 844 | Short cycles (tables) | Find pairs of tables that have both a mandatory (NOT NULL) and not defrerrable foreign key that references to the other table. Such cycles can involve more than two tables but the query detects only cycles with two tables. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 845 | Should the time zone be recorded in case of time or not? | Find all the base table columns that have the type time without time zone or time with time zone. Return the data only if there is at least one column with the type time without time zone and one column with the type time with time zone. | Problem detection | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 846 | Should the time zone be recorded in case of timestamp or not? | Find all the base table columns that have the type timestamp without time zone or timestamp with time zone. Return the data only if there is at least one column with the type timestamp without time zone and one column with the type timestamp with time zone. | Problem detection | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 847 | Simple check constraints with multiple tasks | Find simple check constraints, i.e., check constraints that cover one column that seem to have multiple tasks. The corresponding code smell in case of cleaning code is "G30: Functions Should Do One Thing". (Robert C. Martin, Clean Code) | Problem detection | system catalog base tables only | MIT (opens in new tab) | View | |
| 848 | Simple primary keys that column name does not contain the table name | Find simple primary keys that column name does not contain the table name. The naming should be clear and consistent. | Problem detection | system catalog base tables only | MIT (opens in new tab) | View | |
| 849 | Simplify regex by combining alpha and digit classes | This query identifies regular expressions that can be simplified by consolidating separate character class references. It specifically targets patterns that explicitly match both alphabetic characters ([:alpha:]) and numeric digits ([:digit:], \d, or [0-9]) as separate components within a larger character set (e.g., [[:alpha:][:digit:]]). These distinct classes can be refactored into the single, more concise POSIX character class [:alnum:], which logically represents the union of both. Performing this simplification improves the readability and compactness of the regular expression without altering its behavior. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 850 | Single-column natural primary keys | This query identifies primary keys that consist of a single column and are not system-generated (i.e., they are not associated with a sequence or defined as IDENTITY columns). This pattern is characteristic of a natural primary key, where the key's value is derived from a real-world, user-defined attribute rather than an arbitrary surrogate value. Identifying these keys is crucial for auditing a data model's key strategy and understanding its reliance on meaningful, potentially mutable, business data for entity identification. | General | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 851 | Small tables | Find tables that have one column or zero columns. | General | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 852 | Snake_case violations detected by common suffixes | This query identifies database identifiers (columns, parameters, etc.) that likely violate the snake_case naming convention based on suffix analysis. It flags names ending with common temporal or attributional terms (date, time, by) where the suffix is not immediately preceded by an underscore. This pattern is highly indicative of camelCase (e.g., createdDate, updatedBy) or PascalCase usage. Adhering to snake_case (e.g., created_date, updated_by) is the recommended standard for SQL database schemas to ensure consistency and readability. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 853 | Some candidate key values cannot be used as foreign key values | Find foreign key constraints in case of which some candidate key values cannot be used as foreign key values. Primary key/unique columns and foreign key columns should have the same data type and field size. If, for instance, the primary key column has type INTEGER and foreign key column has type SMALLINT, then one cannot use all the primary key values as foreign key values. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 854 | Some CHECKS are associated with a domain and some with the base table columns that have the domain | Find cases where some CHECKS are associated with a domain and some with the base table columns that have the domain. Avoid duplication of code. Write as little code as possible. If possible, move things "before the brackets" so to say. In this case it means declaring CHECKS at the level of the domain and not at the level of base table columns. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 855 | Some data modification functions return a value and some not | Find as to whether there are data modification routines that return a value as well as data modification routines that do not return a value. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 856 | Something is still to do in routines | Find routines where comments contain TODO phrase. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 857 | Sometimes current_timestamp, sometimes now() | Find as to whether you sometimes use current_timestamp function and sometimes now() function. These implement the same functionality. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 858 | Sometimes extract, sometimes date_part | Find as to whether you sometimes use date_part function and sometimes extract function. These implement the same functionality. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 859 | Sometimes regexp_like, sometimes ~ | Find as to whether you sometimes use regexp_like function and sometimes ~ operator. These implement the same functionality. regexp_like function that was added to PostgreSQL 15 and provides the same functionality as ~ and ~* operators. Try to be consistent. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 860 | Sorting rows based on random values in derived tables | Find derived tables (views and materialized views) that sort rows based on random values. This can be used to find a random subset of rows. It is a computationally expensive operation. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View |