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.
#221. Database object that belong to the public interface (virtual data layer) and that names contain the letters õäöüÕÄÖÜ
INFORMATION_SCHEMA+system catalog base tablesFind database object that belong to the database public interface (virtual data layer - consists of routines and derived tables) and that names contain the letters õäöüÕÄÖÜ (Estonian letters with a diacritic). These letters belong to the Estonian alphabet but do not belong to the ASCII character set. Although permitted by the DBMS, such letters might make it more difficult to use the interface by other programs.
#222. Database object that do not belong to the public interface (virtual data layer) and that names contain the letters õäöüÕÄÖÜ
INFORMATION_SCHEMA+system catalog base tablesFind database object that do not belong to the database public interface (virtual data layer - consists of routines and derived tables) and that names contain the letters õäöüÕÄÖÜ (Estonian letters with a diacritic). These letters belong to the Estonian alphabet but do not belong to the ASCII character set. Although permitted by the DBMS, such letters might make the naming style inconsistent with the naming style of elements that belong to the public interface. If applications access base tables directly, then the letters can cause the same problems as in case of derived tables, i.e., applications may have difficulties with such names.
#223. Data-modifying routines with hardcoded actor or audit identifiers
INFORMATION_SCHEMA+system catalog base tablesThis query identifies data-modifying user-defined routines (functions, procedures, and trigger functions) where audit or actor columns and variables (such as looja, registreerija, viimane_muutja, kustutaja, arhiveerija, kinnitaja, sisestaja, created_by, updated_by, modified_by, deleted_by, approved_by, etc.) are assigned or compared against hardcoded numeric or string literals instead of dynamically determined user identifiers. Hardcoding actor identifiers inside database routines is a serious security, data integrity, and maintainability flaw:
- Compromised audit trails and accountability: Every record created, modified, approved, or archived by the routine is attributed to a fixed placeholder user (e.g.,
1or'admin'), making it impossible to trace who actually performed the action. - Environment fragility and foreign key failures: Hardcoded surrogate Ids (such as
1) may not exist in all environments (development, staging, production), may belong to a completely different user, or may cause foreign key constraint violations if that user account is removed or changed.
#224. Data-modifying (UPDATE or DELETE) routines lacking Optimistic Concurrency Control (row-version checking)
INFORMATION_SCHEMA+system catalog base tablesThis query identifies non-trigger user-defined routines (functions and procedures) that execute UPDATE or DELETE statements without implementing Optimistic Concurrency Control (OCC) via the PostgreSQL xmin system column or a dedicated row-version column (such as rea_versioon, versioon, version, or row_version).
In interactive multi-user applications, a user typically reads a record onto a screen, reviews or edits it (user think-time), and then invokes a database routine to save or delete the record in a new database transaction. Because database locks cannot be held across user think-time, executing an UPDATE or DELETE statement that filters solely by the entity's identifier without verifying that the row's version matches the version originally read by the user exposes the system to the Lost Update anomaly: if another user modifies the record in the meantime, the second transaction will blindly overwrite or delete those intermediate changes without warning.
#225. Data type mismatch in check constraints
system catalog base tables onlyThis query identifies single-column CHECK constraints where the validation logic utilizes operators or functions that are incompatible with the column's native data type. It detects cases where the database must perform implicit casting to evaluate the expression (e.g., performing arithmetic on a TEXT column or string manipulation on a DATE column). Relying on implicit coercion in constraints involves unnecessary computational overhead and frequently indicates a fundamental error in data modeling or constraint formulation.
#226. Data type usage in the base table columns
INFORMATION_SCHEMA onlyGet overview of used data types in the columns of base tables. If the selection is very small then this is a warning sign that perhaps unsuitable types have been used.
#227. Declaratively partitioned tables with one partition
INFORMATION_SCHEMA+system catalog base tablesFind declaratively partitioned tables that have exactly one partition. Declarative partitioning is implemented in PostgreSQL starting from PostgreSQL 10. If there is only one partition, then it raises question as to why the additional complexity associated with partitioning is needed.
#228. Declaratively partitioned tables without partitions
INFORMATION_SCHEMA+system catalog base tablesFind declaratively partitioned tables that do not have any partitions. Declarative partitioning is implemented in PostgreSQL starting from PostgreSQL 10.
#229. Default is NULL
INFORMATION_SCHEMA onlyFind all tables where default value is NULL. NULL is the marker that denotes missing value. Implicitly all columns that do not have a default value have the default NULL. There is no need to specify such default value.
#230. Default should be declared at the level of domain not at the level of base table columns
INFORMATION_SCHEMA+system catalog base tablesFind domains that have been used to define one or more base table non-foreign key columns and all the columns have the same default value that is associated directly with the column not with the domain. Write as little code as possible. If possible, move things "before the brackets" so to say. In this case it means declaring the default value at the level of the domain and not at the level of base table columns. An exception is when the domain is used to define foreign key columns. In this case, it would be appropriate to define the default value at the column level (because different foreign keys could have different default values).
#231. Deferrable constraints
system catalog base tables onlyFind all deferrable constraints.
#232. Deferrable foreign key constraint with a RESTRICT compensating action
system catalog base tables onlyFind deferrable foreign key constraint with ON UPDATE RESTRICT or ON DELETE RESTRICT compensating action. Referential actions are carried out before, and are not part of, the checking of a referential constraint. Deferring a referential constraint defers the checking of the
#233. Definition of a non-minimal superkey instead of a candidate key (based on check constraints)
INFORMATION_SCHEMA+system catalog base tablesCandidate key is a minimal superkey, meaning that it is not possible to remove columns from the candidate key without losing its uniqueness property. One should define primary key's and unique constraints based on candidate keys. Find primary key and unique constraints where a proper subset of columns has a check constraint that permits only one value in the column. The candidate key should involve only columns without such constraint.
#234. Definition of a non-minimal superkey instead of a candidate key (based on enumeration types)
INFORMATION_SCHEMA+system catalog base tablesCandidate key is a minimal superkey, meaning that it is not possible to remove columns from the candidate key without losing its uniqueness property. One should define primary key's and unique constraints based on candidate keys. Find primary key and unique constraints where a proper subset of columns has an enumeration type that permits only one value in the column. The candidate key should involve only columns without such type.
#235. Definition of a non-minimal superkey instead of a candidate key (based on key constraints)
system catalog base tables onlyFind primary key, unique constraints, and exclude constraints wiht only operator = (i.e., sets of columns) that are proper subsets of other primary key, unique, and exclude constraints of the same table. Candidate key is a minimal superkey, meaning that it is not possible to remove columns from the candidate key without losing its uniqueness property. One should define primary key's and unique constraints based on candidate keys, i.e., the keys should not have redundancy in terms of columns.
#236. Definition of a non-minimal superkey instead of a candidate key (based on sequence generators)
INFORMATION_SCHEMA+system catalog base tablesCandidate key is a minimal superkey, meaning that it is not possible to remove columns from the candidate key without losing its uniqueness property. One should define primary key's and unique constraints based on candidate keys. Find primary keys and unique constraints where a proper subset of the key is a column with an associated sequence generator. Most certainly such subset contains unique values. Thus, this subset should be the key, not its superset.
#237. Definition of a non-minimal superkey instead of a candidate key (based on unique indexes)
system catalog base tables onlyFind pairs of non-partial unique indexes where the columns of a index are a proper subset of the columns of another index. Include indexes that support a constraint (primary key, unique, exclude), i.e., these indexes have been automatically created due to the constraint declaration. Exclude the pairs where both participants have been created to support a constraint. Candidate key is a minimal superkey, meaning that it is not possible to remove columns from the candidate key without losing its uniqueness property. One should define keys based on candidate keys, i.e., the keys should not have redundancy in terms of columns. Defining a unique index essentially means defining a key in the table but it is done at the lower level of abstraction.
#238. Delimited identifiers
INFORMATION_SCHEMA+system catalog base tablesDelimited identifiers (quoted identifiers) are case sensitive. Identifiers of database objects should be case insensitive in order to simplify their management.
#239. Depth of referential tree of a schema
system catalog base tables onlyDepth of referential tree of a database schema is the longest referential path between the tables in this schema (Piattini et al., 2001). In other words, it is the biggest value among the DRT(T) values of all the tables of the schema.
#240. Depth of relational tree of a table
system catalog base tables onlyDepth of relational tree of a table T (DRT(T)) is defined by Piattini et al. (2001) as "the longest referential path between tables, from the table T to any other table in the schema". The result may help to classify the data. If the depth is 0, then probably the table contains classifers. Tables with the largest depth probably contain some extra information about main entities.
| # | 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 |
|---|---|---|---|---|---|---|---|
| 221 | Database object that belong to the public interface (virtual data layer) and that names contain the letters õäöüÕÄÖÜ | Find database object that belong to the database public interface (virtual data layer - consists of routines and derived tables) and that names contain the letters õäöüÕÄÖÜ (Estonian letters with a diacritic). These letters belong to the Estonian alphabet but do not belong to the ASCII character set. Although permitted by the DBMS, such letters might make it more difficult to use the interface by other programs. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 222 | Database object that do not belong to the public interface (virtual data layer) and that names contain the letters õäöüÕÄÖÜ | Find database object that do not belong to the database public interface (virtual data layer - consists of routines and derived tables) and that names contain the letters õäöüÕÄÖÜ (Estonian letters with a diacritic). These letters belong to the Estonian alphabet but do not belong to the ASCII character set. Although permitted by the DBMS, such letters might make the naming style inconsistent with the naming style of elements that belong to the public interface. If applications access base tables directly, then the letters can cause the same problems as in case of derived tables, i.e., applications may have difficulties with such names. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 223 | Data-modifying routines with hardcoded actor or audit identifiers | This query identifies data-modifying user-defined routines (functions, procedures, and trigger functions) where audit or actor columns and variables (such as looja, registreerija, viimane_muutja, kustutaja, arhiveerija, kinnitaja, sisestaja, created_by, updated_by, modified_by, deleted_by, approved_by, etc.) are assigned or compared against hardcoded numeric or string literals instead of dynamically determined user identifiers. Hardcoding actor identifiers inside database routines is a serious security, data integrity, and maintainability flaw:
|
Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 224 | Data-modifying (UPDATE or DELETE) routines lacking Optimistic Concurrency Control (row-version checking) | This query identifies non-trigger user-defined routines (functions and procedures) that execute UPDATE or DELETE statements without implementing Optimistic Concurrency Control (OCC) via the PostgreSQL xmin system column or a dedicated row-version column (such as rea_versioon, versioon, version, or row_version). In interactive multi-user applications, a user typically reads a record onto a screen, reviews or edits it (user think-time), and then invokes a database routine to save or delete the record in a new database transaction. Because database locks cannot be held across user think-time, executing an |
Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 225 | Data type mismatch in check constraints | This query identifies single-column CHECK constraints where the validation logic utilizes operators or functions that are incompatible with the column's native data type. It detects cases where the database must perform implicit casting to evaluate the expression (e.g., performing arithmetic on a TEXT column or string manipulation on a DATE column). Relying on implicit coercion in constraints involves unnecessary computational overhead and frequently indicates a fundamental error in data modeling or constraint formulation. | Problem detection | system catalog base tables only | MIT (opens in new tab) | View | |
| 226 | Data type usage in the base table columns | Get overview of used data types in the columns of base tables. If the selection is very small then this is a warning sign that perhaps unsuitable types have been used. | General | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 227 | Declaratively partitioned tables with one partition | Find declaratively partitioned tables that have exactly one partition. Declarative partitioning is implemented in PostgreSQL starting from PostgreSQL 10. If there is only one partition, then it raises question as to why the additional complexity associated with partitioning is needed. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 228 | Declaratively partitioned tables without partitions | Find declaratively partitioned tables that do not have any partitions. Declarative partitioning is implemented in PostgreSQL starting from PostgreSQL 10. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 229 | Default is NULL | Find all tables where default value is NULL. NULL is the marker that denotes missing value. Implicitly all columns that do not have a default value have the default NULL. There is no need to specify such default value. | Problem detection | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 230 | Default should be declared at the level of domain not at the level of base table columns | Find domains that have been used to define one or more base table non-foreign key columns and all the columns have the same default value that is associated directly with the column not with the domain. Write as little code as possible. If possible, move things "before the brackets" so to say. In this case it means declaring the default value at the level of the domain and not at the level of base table columns. An exception is when the domain is used to define foreign key columns. In this case, it would be appropriate to define the default value at the column level (because different foreign keys could have different default values). | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 231 | Deferrable constraints | Find all deferrable constraints. | General | system catalog base tables only | MIT (opens in new tab) | View | |
| 232 | Deferrable foreign key constraint with a RESTRICT compensating action | Find deferrable foreign key constraint with ON UPDATE RESTRICT or ON DELETE RESTRICT compensating action. Referential actions are carried out before, and are not part of, the checking of a referential constraint. Deferring a referential constraint defers the checking of the |
Problem detection | system catalog base tables only | MIT (opens in new tab) | View | |
| 233 | Definition of a non-minimal superkey instead of a candidate key (based on check constraints) | Candidate key is a minimal superkey, meaning that it is not possible to remove columns from the candidate key without losing its uniqueness property. One should define primary key's and unique constraints based on candidate keys. Find primary key and unique constraints where a proper subset of columns has a check constraint that permits only one value in the column. The candidate key should involve only columns without such constraint. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 234 | Definition of a non-minimal superkey instead of a candidate key (based on enumeration types) | Candidate key is a minimal superkey, meaning that it is not possible to remove columns from the candidate key without losing its uniqueness property. One should define primary key's and unique constraints based on candidate keys. Find primary key and unique constraints where a proper subset of columns has an enumeration type that permits only one value in the column. The candidate key should involve only columns without such type. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 235 | Definition of a non-minimal superkey instead of a candidate key (based on key constraints) | Find primary key, unique constraints, and exclude constraints wiht only operator = (i.e., sets of columns) that are proper subsets of other primary key, unique, and exclude constraints of the same table. Candidate key is a minimal superkey, meaning that it is not possible to remove columns from the candidate key without losing its uniqueness property. One should define primary key's and unique constraints based on candidate keys, i.e., the keys should not have redundancy in terms of columns. | Problem detection | system catalog base tables only | MIT (opens in new tab) | View | |
| 236 | Definition of a non-minimal superkey instead of a candidate key (based on sequence generators) | Candidate key is a minimal superkey, meaning that it is not possible to remove columns from the candidate key without losing its uniqueness property. One should define primary key's and unique constraints based on candidate keys. Find primary keys and unique constraints where a proper subset of the key is a column with an associated sequence generator. Most certainly such subset contains unique values. Thus, this subset should be the key, not its superset. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 237 | Definition of a non-minimal superkey instead of a candidate key (based on unique indexes) | Find pairs of non-partial unique indexes where the columns of a index are a proper subset of the columns of another index. Include indexes that support a constraint (primary key, unique, exclude), i.e., these indexes have been automatically created due to the constraint declaration. Exclude the pairs where both participants have been created to support a constraint. Candidate key is a minimal superkey, meaning that it is not possible to remove columns from the candidate key without losing its uniqueness property. One should define keys based on candidate keys, i.e., the keys should not have redundancy in terms of columns. Defining a unique index essentially means defining a key in the table but it is done at the lower level of abstraction. | Problem detection | system catalog base tables only | MIT (opens in new tab) | View | |
| 238 | Delimited identifiers | Delimited identifiers (quoted identifiers) are case sensitive. Identifiers of database objects should be case insensitive in order to simplify their management. | Problem detection | INFORMATION_SCHEMA+system catalog base tables | MIT (opens in new tab) | View | |
| 239 | Depth of referential tree of a schema | Depth of referential tree of a database schema is the longest referential path between the tables in this schema (Piattini et al., 2001). In other words, it is the biggest value among the DRT(T) values of all the tables of the schema. | Sofware measure | system catalog base tables only | MIT (opens in new tab) | View | |
| 240 | Depth of relational tree of a table | Depth of relational tree of a table T (DRT(T)) is defined by Piattini et al. (2001) as "the longest referential path between tables, from the table T to any other table in the schema". The result may help to classify the data. If the depth is 0, then probably the table contains classifers. Tables with the largest depth probably contain some extra information about main entities. | Sofware measure | system catalog base tables only | MIT (opens in new tab) | View |