Catalog of PostgreSQL queries for finding information about a PostgreSQL database and its design problems

AND
AND
AND
ANDFrom where does the query gets its information?
AND
AND

There are 961 queries.

Seq nrNameGoalTypeData sourceLast updateLicense...
1Flag parametersA Boolean parameter may be used to determine what task to fulfill. In this case the routine has multiple tasks and does not satisfy the separation of concerns principle.Problem detectionINFORMATION_SCHEMA+system catalog base tables2021-11-04 10:48MIT License
2Base tables that have a unique constraint but not the primary keyA common style is to declare in each base table one of the candidate keys as the primary key. All the other candidate keys would be alternate keys that will be enforce with the help of UNIQUE + NOT NULL constraints.Problem detectionINFORMATION_SCHEMA only2021-02-25 17:30MIT License
3Perhaps a too long PL/pgSQL routineA large routine may have multiple tasks that should be split between multiple routines, each of which has a more focused task. Find the PL/pgSQL routines where the number of physical lines of code is bigger than 20.Problem detectionINFORMATION_SCHEMA+system catalog base tables2024-01-04 16:38MIT License
4Perhaps a too long SQL routineA large routine may have multiple tasks that should be split between multiple routines that have a more focused task. Find the SQL routines where the number of statements (logical lines of code) is bigger than 5.Problem detectionINFORMATION_SCHEMA+system catalog base tables2024-01-04 16:39MIT License
5Potentially missing PRIMARY KEY or UNIQUE constraints (based on foreign keys)All the keys must be enforced. Find base tables that implement M:N relationship types and that allow multiple relationships of the same type between the same entities.Problem detectionINFORMATION_SCHEMA+system catalog base tables2021-02-25 17:29MIT License
6ROW level BEFORE triggers with RAISE EXCEPTION but without RETURN NULLAlthough RAISE EXCEPTION stops the execution it would be a good style to still return. In this case the return should bring back NULL, i.e., the row will not be processed furtherProblem detectionINFORMATION_SCHEMA+system catalog base tables2021-02-25 17:30MIT License
7Base tables that have a surrogate key and do not have any uniqueness constraintsA surrogate key is a key that consist of one column. The values of this column do not have any meaning for the user and the system generates the values (integers) automatically. In case of defining a surrogate key in a table it is a common mistake to forget declaring existing natural keys in the table. The query discards tables with only one column.Problem detectionINFORMATION_SCHEMA+system catalog base tables2023-10-26 17:47MIT License
8Base tables that have a surrogate key and all its unique constraints have an optional columnA surrogate key is a primary key that consist of one column. The values of this column do not have any meaning for the user and the system usually generates the values (integers) automatically. In case of defining a surrogate key in a table it is a common mistake to forget declaring existing natural keys in the table. If a key covers an optional column then it does not prevent duplicate rows where some values are missing and other values are equal. Because NULL is not a value and is not duplicate of another NULL the, follwing is possible: CREATE TABLE Uniq(a INTEGER NOT NULL,
b INTEGER,
CONSTRAINT ak_uniq UNIQUE (a, b));

INSERT INTO Uniq(a, b) VALUES (1, NULL);
INSERT INTO Uniq(a, b) VALUES (1, NULL);
Problem detectionINFORMATION_SCHEMA+system catalog base tables2023-10-21 11:54MIT License
9Unnecessary privileges to use trigger functionsA user that corresponds to an application does not have to have privileges to use trigger functions. If it has these, then it violates the principle of least privilege.Problem detectionINFORMATION_SCHEMA+system catalog base tables2021-02-25 17:30MIT License
10Trigger routines with TG_OP variable that are not associated with a suitable triggerAutomatically defined TG_OP variable in a trigger function has data type text. Its value is a string of INSERT, UPDATE, DELETE, or TRUNCATE telling for which operation the trigger was fired. Find the routines that according to the TG_OP value must react to a certain operation but the routine is not associated with any triggers that are fired by the operation. For instance, the routine specifies reaction to DELETE operation but the routine is not associated with any DELETE trigger.Problem detectionINFORMATION_SCHEMA+system catalog base tables2021-12-25 01:26MIT License
11Do not create user-defined routines that have the same name as some installed extension routineAvoid creating user-defined routines that have the same name as some extension routine because it may cause confusion.Problem detectionINFORMATION_SCHEMA+system catalog base tables2021-10-25 16:14MIT License
12User-defined routines that have the same name as some system-defined routine.Avoid creating user-defined routines that have the same name as some system-defined routine because it may cause confusion.Problem detectionINFORMATION_SCHEMA+system catalog base tables2021-02-25 17:30MIT License
13NOT IN or <> ALL in routinesAvoid using NOT IN or <>ALL with a non-correlated subquery in PostgreSQL because the query performance will be very poor.Problem detectionINFORMATION_SCHEMA+system catalog base tables2021-10-25 16:42MIT License
14NOT IN or <> ALL in derived tablesAvoid using NOT IN or <>ALL with a non-correlated subquery in PostgreSQL because the query performance will be very poor, especially in case of large data sizes.Problem detectionINFORMATION_SCHEMA+system catalog base tables2021-02-25 17:30MIT License
15Too generic names (routines)"Avoid using the same word for two purposes. Using the same term for two different ideas is essentially a pun" (Robert C. Martin, Clean Code) Do not use the Estonian words like 'lisa', 'muuda', 'kustuta' or the corresponding English words 'add', 'delete', 'update' as the names of routines because it would make the code much less understandable. What is the task of the routine f_add? Register people? Register orders? What? Do not refer to the generic concepts like data and information because all routines work with these.Problem detectionINFORMATION_SCHEMA+system catalog base tables2023-01-07 20:38MIT License
16Non-updatable views that have data modification privilegesBe precise and do not give impossible privileges.Problem detectionINFORMATION_SCHEMA+system catalog base tables2021-02-25 17:29MIT License
17Use invocation of a precise function instead of casting in a default value expressionBe 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 detectionINFORMATION_SCHEMA only2021-02-25 17:29MIT License
18Definition 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 detectionINFORMATION_SCHEMA+system catalog base tables2021-02-25 17:30MIT License
19Definition 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 detectionINFORMATION_SCHEMA+system catalog base tables2021-02-25 17:29MIT License
20Definition 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 detectionINFORMATION_SCHEMA+system catalog base tables2021-03-07 20:56MIT License