Filter Queries

Found 1077 queries.

Page 26 of 54
  • 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.

#501. Median and average of the length of names of database objects

INFORMATION_SCHEMA+system catalog base tables

"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." (Robert C. Martin, Clean Code) Names should be expressive. Find the median length and average (arithmetic mean) length of the names (identifiers) of user-defined database objects. The values could be used to compare different databases.

Sofware measure License: MIT (opens in new tab)

#502. Median and average of the length of names of database objects by the object type

INFORMATION_SCHEMA+system catalog base tables

"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." (Robert C. Martin, Clean Code) Names should be expressive. Find the median length and average (arithmetic mean) length of the names (identifiers) of user-defined database objects by the object type. The values could be used to compare different databases.

Sofware measure License: MIT (opens in new tab)

#503. Middle-man

INFORMATION_SCHEMA+system catalog base tables

Find a routine that's only task is to invoke another routine. If a routine performs only one action, delegating work to another routine, why does it exist at all?

Problem detection License: MIT (opens in new tab)

#504. Minimum tuple length required before trying to move long column values into TOAST tables has been changed

INFORMATION_SCHEMA+system catalog base tables

Find base tables in case of which toast_tuple_target storage parameter value is not the default value (2040). "Changing this value may not be useful for very short or very long rows. Note that the default setting is often close to optimal, and it is possible that setting this parameter could have negative effects in some cases. " Make sure that the parameter has an optimal value.

General License: MIT (opens in new tab)

#505. Missing dynamic values in exception details

INFORMATION_SCHEMA+system catalog base tables

This query identifies PL/pgSQL routines that invoke RAISE EXCEPTION but fail to include dynamic values (such as the problematic data itself) in the DETAIL clause. Providing only static text in error details is an anti-pattern, as it makes debugging significantly harder. Developers and client applications need to see the actual rejected values to quickly understand and fix the underlying issue.

Problem detection License: MIT (opens in new tab)

#506. Missing error context in exceptions

INFORMATION_SCHEMA+system catalog base tables

This query identifies PL/pgSQL routines that use the RAISE EXCEPTION statement but fail to provide additional error context, such as ERRCODE, DETAIL, HINT, or CONSTRAINT. Defining these supplementary clauses is a best practice in PL/pgSQL, as it provides developers and client applications with essential diagnostic information for robust error handling.

Problem detection License: MIT (opens in new tab)

#507. Missing foreign keys on user reference columns

INFORMATION_SCHEMA+system catalog base tables

This query identifies potential missing foreign key constraints by searching for unconstrained base table columns whose names suggest they record references to a user (e.g., user_id, created_by). It specifically flags columns that are not part of any primary key, unique constraint, or foreign key constraint. To minimize false positives, the query intelligently excludes columns configured with CURRENT_USER or SESSION_USER default values, as these often represent system-level audit logs rather than relational application data. Missing foreign keys on user references can lead to orphaned records and compromise referential integrity.

Problem detection License: MIT (opens in new tab)

#508. Missing table name in trigger exception constraints

INFORMATION_SCHEMA+system catalog base tables

This query identifies trigger routines that use the RAISE EXCEPTION statement and specify a CONSTRAINT clause, but the provided constraint name does not include the name of the table to which the trigger is attached. Following a naming convention where constraint names incorporate the parent table's name is a best practice. It ensures that constraints are easily traceable and globally identifiable within the database schema when errors occur.

Problem detection License: MIT (opens in new tab)

#509. Missing USAGE privileges on schema

INFORMATION_SCHEMA+system catalog base tables

If a user has a privilege to use a schema object, then the user must also have the usage privilege on the schema that contains the object.

Problem detection License: MIT (opens in new tab)

#510. Multi-column CHECK constraints with unnecessary NULL checks

INFORMATION_SCHEMA+system catalog base tables

This query identifies multiple-column CHECK constraints that explicitly check for NULL values. In general, constraint definitions should be kept as simple as possible. Because a NULL value causes a logical condition to evaluate to UNKNOWN—and CHECK constraints inherently allow rows that evaluate to either TRUE or UNKNOWN—there is usually no need to explicitly allow missing values. For instance, instead of writing CHECK (last_update_time IS NULL OR last_update_time >= creation_time), the constraint should simply be written as CHECK (last_update_time >= creation_time). However, a valid exception exists for implication rules (P ⇒ Q), which can be rewritten as NOT (P) OR Q. For example, the constraint CHECK (NOT (product IS NOT NULL) OR service IS NULL) properly enforces the rule that if a product is present, the service must be NULL. Such logical constructs are entirely appropriate.

Problem detection License: MIT (opens in new tab)

#511. Multiple columns in exception COLUMN clause

INFORMATION_SCHEMA+system catalog base tables

This query identifies PL/pgSQL routines that invoke RAISE EXCEPTION and specify multiple columns within the COLUMN error context clause. This is an anti-pattern because PostgreSQL's column diagnostic field is designed to hold a single column identifier. Providing a list of columns in this field breaks standard error parsing, making it difficult for client applications to map the error to a specific user interface field.

Problem detection License: MIT (opens in new tab)

#512. Multiple deletes from the same table in a routine

INFORMATION_SCHEMA+system catalog base tables

Code should be as compact as possible and system should make as little work as necessary in order to solve a task. Thus, instead of deleting different rows of the same table with different DELETE statements one should try to do it with one statement. The query excludes routines where IF statement is used.

Problem detection License: MIT (opens in new tab)

#513. Multiple RETURNING clauses in a SQL function

INFORMATION_SCHEMA+system catalog base tables

Find SQL functions that have multiple statements with the RETURNING clause.

Problem detection License: MIT (opens in new tab)

#514. Multiple selects from the same table in a routine

INFORMATION_SCHEMA+system catalog base tables

Code should be as compact as possible and system should make as little work as necessary in order to solve a task. Thus, instead of selecting different fields of the same row with different SELECT INTO statements one should try to do it with one statement.

Problem detection License: MIT (opens in new tab)

#515. Multiple simple keys with integer values

INFORMATION_SCHEMA+system catalog base tables

This query identifies base tables with a potentially redundant key structure, specifically those having more than one PRIMARY KEY or UNIQUE constraint defined on a single integer-type column. This pattern may suggest the presence of multiple surrogate keys for the same entity, which can indicate overcomplicated data model. A single entity should typically have only one system-generated identifier to maintain schema clarity, simplify join logic, and avoid redundancy. The presence of multiple such keys warrants a review to determine if one is superfluous.

Problem detection License: MIT (opens in new tab)

#516. Multiple updates of the same table in a routine

INFORMATION_SCHEMA+system catalog base tables

Code should be as compact as possible and system should make as little work as necessary in order to solve a task. Thus, instead of updating different fields of the same table with different UPDATE statements one should try to do it with one statement.

Problem detection License: MIT (opens in new tab)

#517. Name and description maximum length

INFORMATION_SCHEMA+system catalog base tables

Find tables where is both a column for registering name and description. Find the permitted maximum field size in these columns. Take into account that the maximum length may be controlled by using a CHECK constraint. Make sure that the permitted maximum field sizes are sufficiently different.

General License: MIT (opens in new tab)

#518. Name contains only consonants and digits

INFORMATION_SCHEMA+system catalog base tables

Find names of database objects that contain only consonants and digits.

Problem detection License: MIT (opens in new tab)

#519. Name does not contain any vowels

INFORMATION_SCHEMA+system catalog base tables

Find names of database objects that do not contain any vowels.

Problem detection License: MIT (opens in new tab)

#520. Name does not contain any vowels (aggregate view)

INFORMATION_SCHEMA+system catalog base tables

Find aggregate information about the names of database objects that do not contain any vowels.

Sofware measure License: MIT (opens in new tab)
# 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
501 Median and average of the length of names of database objects "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." (Robert C. Martin, Clean Code) Names should be expressive. Find the median length and average (arithmetic mean) length of the names (identifiers) of user-defined database objects. The values could be used to compare different databases. Sofware measure INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
502 Median and average of the length of names of database objects by the object type "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." (Robert C. Martin, Clean Code) Names should be expressive. Find the median length and average (arithmetic mean) length of the names (identifiers) of user-defined database objects by the object type. The values could be used to compare different databases. Sofware measure INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
503 Middle-man Find a routine that's only task is to invoke another routine. If a routine performs only one action, delegating work to another routine, why does it exist at all? Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
504 Minimum tuple length required before trying to move long column values into TOAST tables has been changed Find base tables in case of which toast_tuple_target storage parameter value is not the default value (2040). "Changing this value may not be useful for very short or very long rows. Note that the default setting is often close to optimal, and it is possible that setting this parameter could have negative effects in some cases. " Make sure that the parameter has an optimal value. General INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
505 Missing dynamic values in exception details This query identifies PL/pgSQL routines that invoke RAISE EXCEPTION but fail to include dynamic values (such as the problematic data itself) in the DETAIL clause. Providing only static text in error details is an anti-pattern, as it makes debugging significantly harder. Developers and client applications need to see the actual rejected values to quickly understand and fix the underlying issue. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
506 Missing error context in exceptions This query identifies PL/pgSQL routines that use the RAISE EXCEPTION statement but fail to provide additional error context, such as ERRCODE, DETAIL, HINT, or CONSTRAINT. Defining these supplementary clauses is a best practice in PL/pgSQL, as it provides developers and client applications with essential diagnostic information for robust error handling. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
507 Missing foreign keys on user reference columns This query identifies potential missing foreign key constraints by searching for unconstrained base table columns whose names suggest they record references to a user (e.g., user_id, created_by). It specifically flags columns that are not part of any primary key, unique constraint, or foreign key constraint. To minimize false positives, the query intelligently excludes columns configured with CURRENT_USER or SESSION_USER default values, as these often represent system-level audit logs rather than relational application data. Missing foreign keys on user references can lead to orphaned records and compromise referential integrity. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
508 Missing table name in trigger exception constraints This query identifies trigger routines that use the RAISE EXCEPTION statement and specify a CONSTRAINT clause, but the provided constraint name does not include the name of the table to which the trigger is attached. Following a naming convention where constraint names incorporate the parent table's name is a best practice. It ensures that constraints are easily traceable and globally identifiable within the database schema when errors occur. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
509 Missing USAGE privileges on schema If a user has a privilege to use a schema object, then the user must also have the usage privilege on the schema that contains the object. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
510 Multi-column CHECK constraints with unnecessary NULL checks This query identifies multiple-column CHECK constraints that explicitly check for NULL values. In general, constraint definitions should be kept as simple as possible. Because a NULL value causes a logical condition to evaluate to UNKNOWN—and CHECK constraints inherently allow rows that evaluate to either TRUE or UNKNOWN—there is usually no need to explicitly allow missing values. For instance, instead of writing CHECK (last_update_time IS NULL OR last_update_time >= creation_time), the constraint should simply be written as CHECK (last_update_time >= creation_time). However, a valid exception exists for implication rules (P ⇒ Q), which can be rewritten as NOT (P) OR Q. For example, the constraint CHECK (NOT (product IS NOT NULL) OR service IS NULL) properly enforces the rule that if a product is present, the service must be NULL. Such logical constructs are entirely appropriate. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
511 Multiple columns in exception COLUMN clause This query identifies PL/pgSQL routines that invoke RAISE EXCEPTION and specify multiple columns within the COLUMN error context clause. This is an anti-pattern because PostgreSQL's column diagnostic field is designed to hold a single column identifier. Providing a list of columns in this field breaks standard error parsing, making it difficult for client applications to map the error to a specific user interface field. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
512 Multiple deletes from the same table in a routine Code should be as compact as possible and system should make as little work as necessary in order to solve a task. Thus, instead of deleting different rows of the same table with different DELETE statements one should try to do it with one statement. The query excludes routines where IF statement is used. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
513 Multiple RETURNING clauses in a SQL function Find SQL functions that have multiple statements with the RETURNING clause. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
514 Multiple selects from the same table in a routine Code should be as compact as possible and system should make as little work as necessary in order to solve a task. Thus, instead of selecting different fields of the same row with different SELECT INTO statements one should try to do it with one statement. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
515 Multiple simple keys with integer values This query identifies base tables with a potentially redundant key structure, specifically those having more than one PRIMARY KEY or UNIQUE constraint defined on a single integer-type column. This pattern may suggest the presence of multiple surrogate keys for the same entity, which can indicate overcomplicated data model. A single entity should typically have only one system-generated identifier to maintain schema clarity, simplify join logic, and avoid redundancy. The presence of multiple such keys warrants a review to determine if one is superfluous. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
516 Multiple updates of the same table in a routine Code should be as compact as possible and system should make as little work as necessary in order to solve a task. Thus, instead of updating different fields of the same table with different UPDATE statements one should try to do it with one statement. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
517 Name and description maximum length Find tables where is both a column for registering name and description. Find the permitted maximum field size in these columns. Take into account that the maximum length may be controlled by using a CHECK constraint. Make sure that the permitted maximum field sizes are sufficiently different. General INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
518 Name contains only consonants and digits Find names of database objects that contain only consonants and digits. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
519 Name does not contain any vowels Find names of database objects that do not contain any vowels. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
520 Name does not contain any vowels (aggregate view) Find aggregate information about the names of database objects that do not contain any vowels. Sofware measure INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View