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.
#181. 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.
#182. 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.
#183. Stating the obvious (column names)
INFORMATION_SCHEMA onlyFind the names of columns where the name of the column contains a part of the name of the data type of the column. For instance, the query finds columns, were the name contains fragments integer_ or _integer.
#184. Storing a duration as time
INFORMATION_SCHEMA onlyFind columns of base and foreign tables that based on the column names are used to register durations but the type of the column is time. "It is possible to use a TIME data type if the duration is less than 24 hours, but this is not what the type is intended for, and can be the cause of confusion for the next person who has to maintain your code."
#185. Storing a duration rather than a point in time
INFORMATION_SCHEMA onlyFind columns of base and foreign tables that based on the column names and types are used to register start time and duration rather than start time and end time.
#186. Storing file content in the database
INFORMATION_SCHEMA onlyFind columns that probably store content of files in the database.
#187. System-generated domain CHECK constraint names
INFORMATION_SCHEMA onlyFind the names of domain CHECK constraints that have been system-generated. 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.
#188. Table check constraints with regular expressions
INFORMATION_SCHEMA onlyFind all CHECK constraints (except NOT NULL) that are associated with a base table or a foreign table column and use a regular expression. It is useful to enforce as many constraints at database level as possible. In this way one improves data quality as well as gives extra information to the database users (including the DBMS engines, development environments, and applications).
#189. Table columns that are associated with a sequence generator
INFORMATION_SCHEMA onlySurrogate key values must be generated by using the system (the sequence generator mechanism in case of PostgreSQL). If there is no usage of sequence generators, then there is a question as to whether there are no surrogate keys in the database at all (could be possible and OK) or (more probable) developers have forgotten to implement the generation of surrogate keys.
#190. Table columns with NOT VALID CHECK constraints
INFORMATION_SCHEMA onlyFind CHECK constraints of base table and foreign table columns that are not valid. These constraints have been created so that the existing data has not been checked against the constraint. It could be deliberate in case of legacy systems that have data quality problems. However, ideally all the data in the table conforms to the constraint.
#191. Table privileges
INFORMATION_SCHEMA onlyCheck as to whether there are no unnecessary privileges.
#192. Table privileges have been granted to PUBLIC
INFORMATION_SCHEMA onlyYou should follow the principle of least privilege and thus not have in your database tables that usage privileges are granted to the pseudo-role PUBLIC, i.e., to all the database users now and in the future.
#193. The maximum number of characters may be missing
INFORMATION_SCHEMA onlyPerhaps the character maximum length has been omitted accidentally, i.e., one wrote VARCHAR instead of VARCHAR(n) where n is the maximum permitted number of characters in the field value. VARCHAR and TEXT are synonyms.
#194. The number and percentage of base tables where all the non-primary key columns are optional
INFORMATION_SCHEMA onlyFind the number and percentage of base tables where all the non-primary key columns are optional
#195. The number and percentage of base tables without CHECK constraints
INFORMATION_SCHEMA onlyFind the extent in which data integrity is checked at the database level. Find the number and percentage of base tables that do not have any associated CHECK constraints.
#196. The number and percentage of base tables without keys
INFORMATION_SCHEMA onlyFind the extent in which repeating rows are permitted in the database. Find the number and percentage (from the total number of base tables) of base tables that do not have the PRIMARY KEY constraint and also do not have any UNIQUE constraints.
#197. The number and percentage of optinal columns in base tables
INFORMATION_SCHEMA onlyFind the number and percentage of optinal columns in base tables
#198. The number of base table columns based on data type
INFORMATION_SCHEMA onlyFind the number of base table columns based on data type.
#199. The number of base table columns by type category
INFORMATION_SCHEMA onlyFind the number of base table columns based on the category of data type that the columns have.
#200. The number of default values
INFORMATION_SCHEMA onlyFind the total number of columns with a default value as well as the number of columns with different kinds of default values (the number of columns where the default is used to implement surrogate key, the number of columns where the default is not used to implement surrogate key, the number of columns with a static default value, the number of columns with a dynamic default value).
| # | Name(activate to sort ascending) | Goal(activate to sort ascending) | Type(activate to sort ascending) | Data source(sorted ascending, activate to sort descending) | Last update(activate to sort ascending) | License | Actions |
|---|---|---|---|---|---|---|---|
| 181 | 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 | |
| 182 | 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 | |
| 183 | Stating the obvious (column names) | Find the names of columns where the name of the column contains a part of the name of the data type of the column. For instance, the query finds columns, were the name contains fragments integer_ or _integer. | Problem detection | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 184 | Storing a duration as time | Find columns of base and foreign tables that based on the column names are used to register durations but the type of the column is time. "It is possible to use a TIME data type if the duration is less than 24 hours, but this is not what the type is intended for, and can be the cause of confusion for the next person who has to maintain your code." | Problem detection | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 185 | Storing a duration rather than a point in time | Find columns of base and foreign tables that based on the column names and types are used to register start time and duration rather than start time and end time. | Problem detection | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 186 | Storing file content in the database | Find columns that probably store content of files in the database. | General | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 187 | System-generated domain CHECK constraint names | Find the names of domain CHECK constraints that have been system-generated. 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. | Problem detection | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 188 | Table check constraints with regular expressions | Find all CHECK constraints (except NOT NULL) that are associated with a base table or a foreign table column and use a regular expression. It is useful to enforce as many constraints at database level as possible. In this way one improves data quality as well as gives extra information to the database users (including the DBMS engines, development environments, and applications). | General | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 189 | Table columns that are associated with a sequence generator | Surrogate key values must be generated by using the system (the sequence generator mechanism in case of PostgreSQL). If there is no usage of sequence generators, then there is a question as to whether there are no surrogate keys in the database at all (could be possible and OK) or (more probable) developers have forgotten to implement the generation of surrogate keys. | General | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 190 | Table columns with NOT VALID CHECK constraints | Find CHECK constraints of base table and foreign table columns that are not valid. These constraints have been created so that the existing data has not been checked against the constraint. It could be deliberate in case of legacy systems that have data quality problems. However, ideally all the data in the table conforms to the constraint. | Problem detection | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 191 | Table privileges | Check as to whether there are no unnecessary privileges. | General | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 192 | Table privileges have been granted to PUBLIC | You should follow the principle of least privilege and thus not have in your database tables that usage privileges are granted to the pseudo-role PUBLIC, i.e., to all the database users now and in the future. | Problem detection | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 193 | The maximum number of characters may be missing | Perhaps the character maximum length has been omitted accidentally, i.e., one wrote VARCHAR instead of VARCHAR(n) where n is the maximum permitted number of characters in the field value. VARCHAR and TEXT are synonyms. | Problem detection | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 194 | The number and percentage of base tables where all the non-primary key columns are optional | Find the number and percentage of base tables where all the non-primary key columns are optional | Sofware measure | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 195 | The number and percentage of base tables without CHECK constraints | Find the extent in which data integrity is checked at the database level. Find the number and percentage of base tables that do not have any associated CHECK constraints. | Sofware measure | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 196 | The number and percentage of base tables without keys | Find the extent in which repeating rows are permitted in the database. Find the number and percentage (from the total number of base tables) of base tables that do not have the PRIMARY KEY constraint and also do not have any UNIQUE constraints. | Sofware measure | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 197 | The number and percentage of optinal columns in base tables | Find the number and percentage of optinal columns in base tables | Sofware measure | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 198 | The number of base table columns based on data type | Find the number of base table columns based on data type. | Sofware measure | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 199 | The number of base table columns by type category | Find the number of base table columns based on the category of data type that the columns have. | Sofware measure | INFORMATION_SCHEMA only | MIT (opens in new tab) | View | |
| 200 | The number of default values | Find the total number of columns with a default value as well as the number of columns with different kinds of default values (the number of columns where the default is used to implement surrogate key, the number of columns where the default is not used to implement surrogate key, the number of columns with a static default value, the number of columns with a dynamic default value). | Sofware measure | INFORMATION_SCHEMA only | MIT (opens in new tab) | View |