Filter Queries

Found 1077 queries.

Page 33 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.

#641. PL/pgSQL functions with consecutive RETURN clauses

INFORMATION_SCHEMA+system catalog base tables

Find PL/pgSQL functions with consecutive RETURN clauses. Only the first RETURN will be used, others are unnecessary.

Problem detection License: MIT (opens in new tab)

#642. PL/pgSQL functions without the RETURN clause

INFORMATION_SCHEMA+system catalog base tables

The return value of a function cannot be left undefined. If control reaches the end of the top-level block of the function without hitting a RETURN statement, a run-time error will occur. This restriction does not apply to functions with output parameters and functions returning void, however. In those cases a RETURN statement is automatically executed if the top-level block finishes. It also does not apply to trigger functions that only task is to raise an exception.

Problem detection License: MIT (opens in new tab)

#643. PL/pgSQL routines that use a cursor

INFORMATION_SCHEMA+system catalog base tables

Working with sets of rows rather than processing each row separately is more effective.

General License: MIT (opens in new tab)

#644. PL/pgSQL routine with plain SELECT

INFORMATION_SCHEMA+system catalog base tables

Find PL/pgSQL that contain a SELECT statement that is not a SELECT … INTO statement. This is not permitted in PL/pgSQL routines.

Problem detection License: MIT (opens in new tab)

#645. Pointlessly returned value

INFORMATION_SCHEMA+system catalog base tables

The value that is returned by a function should depend on something. If you do not have anything meaningful to return (for instance, the function always returns true, false, NULL, or the same number), then write VOID instead of the return type.

Problem detection License: MIT (opens in new tab)

#646. Polymorphic routines

INFORMATION_SCHEMA+system catalog base tables

Find routines that have a parameter (input or output) that can have values from different types. This parameter has one of the PostgreSQL polymorphic types. The set of polymorphic types in PostgreSQL is a proper subset of its pseudo-types. The use of such a parameter allows a single routine definition to operate on many different data types, with the specific data type(s) being determined by the data types actually passed to it in a particular call.

General License: MIT (opens in new tab)

#647. Positional argument usage in multi-parameter routine calls

INFORMATION_SCHEMA+system catalog base tables

This query audits user-defined routine invocations to enforce named parameter notation, specifically targeting calls to routines with multiple input parameters. It identifies invocations using positional notation (e.g., func(a, b)), which couples the calling logic to the specific order of the callee's signature. Crucially, the query excludes invocations of routines that accept a single input parameter. In single-arity contexts, positional notation is structurally unambiguous and widely accepted. The focus is strictly on multi-parameter calls where positional notation increases the risk of argument misalignment during refactoring.

Problem detection License: MIT (opens in new tab)

#648. Positional parameter references in routine bodies

INFORMATION_SCHEMA+system catalog base tables

This query identifies user-defined routines (functions and procedures) whose bodies reference input parameters using positional notations (such as $1, $2) rather than explicit parameter names. While positional references are syntactically valid in PostgreSQL SQL and PL/pgSQL routines, they represent a significant code-maintenance anti-pattern. Relying on positional placeholders obscures the business intent of variables and severely degrades code evolvability: adding, reordering, or removing parameters during future refactoring can easily introduce subtle, silent logic errors.

Problem detection License: MIT (opens in new tab)

#649. Potentially a classifier is missing (based on field sizes)

INFORMATION_SCHEMA+system catalog base tables

Find columns that are not covered by a primary key, unique, and foreign key constraint but have a textual type with the maximum field size 3 or less.

General License: MIT (opens in new tab)

#650. Potentially missing PRIMARY KEY or UNIQUE constraints (based on column names)

INFORMATION_SCHEMA+system catalog base tables

Find columns of base tables that name refers to the possibility that it contains unique values but the column does not belong to any PRIMARY KEY/UNIQUE constraint. If something has to be unique, then it must be said to the system so that it could use the information for internal optimizations and enforce the constraint.

Problem detection License: MIT (opens in new tab)

#651. Potentially missing PRIMARY KEY or UNIQUE constraints (based on foreign keys)

INFORMATION_SCHEMA+system catalog base tables

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 detection License: MIT (opens in new tab)

#652. Potentially missing PRIMARY KEY or UNIQUE constraints (based on sequence generators)

INFORMATION_SCHEMA+system catalog base tables

Find columns of base tables that contain automatically generated unique values but do not belong to any PRIMARY KEY/UNIQUE constraint. If something has to be unique, then it must be said to the system so that it could use the information for internal optimizations and enforce the constraint.

Problem detection License: MIT (opens in new tab)

#653. Potentially missing PRIMARY KEY or UNIQUE constraints (based on UUIDs)

INFORMATION_SCHEMA+system catalog base tables

If something has to be unique, then it must be said to the system so that it could use the information for internal optimizations and enforce the constraint. Find columns that contain Universally Unique Identifiers but are not a part of any simple PRIMARY KEY/UNIQUE constraint and are also not part of a foreign key.

Problem detection License: MIT (opens in new tab)

#654. Potentially missing sequence generators (based on column names and types)

INFORMATION_SCHEMA+system catalog base tables

Find surrogate key columns that do not have an associated sequence generator. Surrogate key values must be generated by using the system (the sequence generator mechanism in case of PostgreSQL). If there are no 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.

Problem detection License: MIT (opens in new tab)

#655. Potentially unnecessary use of sequence generators

INFORMATION_SCHEMA+system catalog base tables

Find simple natural key columns that are associated with a sequence generator.

Problem detection License: MIT (opens in new tab)

#656. Precise comparison with pattern matching in CHECK constraints

INFORMATION_SCHEMA+system catalog base tables

Find CHECK constraints that use precise comparison (= or <>) with a regular expression or LIKE pattern.

Problem detection License: MIT (opens in new tab)

#657. Predefined character classes must be between double square brackets

INFORMATION_SCHEMA+system catalog base tables

Find regular expressions that do not have predefined character classes between double square brackets, e.g., [:digit:] instead of [[:digit:]].

Problem detection License: MIT (opens in new tab)

#658. Prefer Polymorphism to If/Else or Switch/Case

INFORMATION_SCHEMA+system catalog base tables

Find routines with IF/ELSE or SWITCH/CASE statements. If your routine has a multipart IF/CASE statement, then perhaps it has multiple tasks and it violates the separation of concerns and single responsibilities principles.

Problem detection License: MIT (opens in new tab)

#659. Prefer Polymorphism to If/Else or Switch/Case (2)

INFORMATION_SCHEMA+system catalog base tables

Find routines with multiple raise exception commands. Perhaps it has multiple tasks and it violates the separation of concerns and single responsibilities principles.

Problem detection License: MIT (opens in new tab)

#660. Prefixes in the names of database objects

INFORMATION_SCHEMA+system catalog base tables

Find for different types of database objects all the prefixes that are used in different names. One should be consistent in naming, including in the use of prefixes. If you use prefix in the name of a database object, then it could refer to the type of the database object. Do not use different prefixes in the names of database objects that have the same type.

General 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
641 PL/pgSQL functions with consecutive RETURN clauses Find PL/pgSQL functions with consecutive RETURN clauses. Only the first RETURN will be used, others are unnecessary. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
642 PL/pgSQL functions without the RETURN clause The return value of a function cannot be left undefined. If control reaches the end of the top-level block of the function without hitting a RETURN statement, a run-time error will occur. This restriction does not apply to functions with output parameters and functions returning void, however. In those cases a RETURN statement is automatically executed if the top-level block finishes. It also does not apply to trigger functions that only task is to raise an exception. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
643 PL/pgSQL routines that use a cursor Working with sets of rows rather than processing each row separately is more effective. General INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
644 PL/pgSQL routine with plain SELECT Find PL/pgSQL that contain a SELECT statement that is not a SELECT … INTO statement. This is not permitted in PL/pgSQL routines. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
645 Pointlessly returned value The value that is returned by a function should depend on something. If you do not have anything meaningful to return (for instance, the function always returns true, false, NULL, or the same number), then write VOID instead of the return type. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
646 Polymorphic routines Find routines that have a parameter (input or output) that can have values from different types. This parameter has one of the PostgreSQL polymorphic types. The set of polymorphic types in PostgreSQL is a proper subset of its pseudo-types. The use of such a parameter allows a single routine definition to operate on many different data types, with the specific data type(s) being determined by the data types actually passed to it in a particular call. General INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
647 Positional argument usage in multi-parameter routine calls This query audits user-defined routine invocations to enforce named parameter notation, specifically targeting calls to routines with multiple input parameters. It identifies invocations using positional notation (e.g., func(a, b)), which couples the calling logic to the specific order of the callee's signature. Crucially, the query excludes invocations of routines that accept a single input parameter. In single-arity contexts, positional notation is structurally unambiguous and widely accepted. The focus is strictly on multi-parameter calls where positional notation increases the risk of argument misalignment during refactoring. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
648 Positional parameter references in routine bodies This query identifies user-defined routines (functions and procedures) whose bodies reference input parameters using positional notations (such as $1, $2) rather than explicit parameter names. While positional references are syntactically valid in PostgreSQL SQL and PL/pgSQL routines, they represent a significant code-maintenance anti-pattern. Relying on positional placeholders obscures the business intent of variables and severely degrades code evolvability: adding, reordering, or removing parameters during future refactoring can easily introduce subtle, silent logic errors. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
649 Potentially a classifier is missing (based on field sizes) Find columns that are not covered by a primary key, unique, and foreign key constraint but have a textual type with the maximum field size 3 or less. General INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
650 Potentially missing PRIMARY KEY or UNIQUE constraints (based on column names) Find columns of base tables that name refers to the possibility that it contains unique values but the column does not belong to any PRIMARY KEY/UNIQUE constraint. If something has to be unique, then it must be said to the system so that it could use the information for internal optimizations and enforce the constraint. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
651 Potentially 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 detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
652 Potentially missing PRIMARY KEY or UNIQUE constraints (based on sequence generators) Find columns of base tables that contain automatically generated unique values but do not belong to any PRIMARY KEY/UNIQUE constraint. If something has to be unique, then it must be said to the system so that it could use the information for internal optimizations and enforce the constraint. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
653 Potentially missing PRIMARY KEY or UNIQUE constraints (based on UUIDs) If something has to be unique, then it must be said to the system so that it could use the information for internal optimizations and enforce the constraint. Find columns that contain Universally Unique Identifiers but are not a part of any simple PRIMARY KEY/UNIQUE constraint and are also not part of a foreign key. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
654 Potentially missing sequence generators (based on column names and types) Find surrogate key columns that do not have an associated sequence generator. Surrogate key values must be generated by using the system (the sequence generator mechanism in case of PostgreSQL). If there are no 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. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
655 Potentially unnecessary use of sequence generators Find simple natural key columns that are associated with a sequence generator. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
656 Precise comparison with pattern matching in CHECK constraints Find CHECK constraints that use precise comparison (= or <>) with a regular expression or LIKE pattern. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
657 Predefined character classes must be between double square brackets Find regular expressions that do not have predefined character classes between double square brackets, e.g., [:digit:] instead of [[:digit:]]. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
658 Prefer Polymorphism to If/Else or Switch/Case Find routines with IF/ELSE or SWITCH/CASE statements. If your routine has a multipart IF/CASE statement, then perhaps it has multiple tasks and it violates the separation of concerns and single responsibilities principles. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
659 Prefer Polymorphism to If/Else or Switch/Case (2) Find routines with multiple raise exception commands. Perhaps it has multiple tasks and it violates the separation of concerns and single responsibilities principles. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
660 Prefixes in the names of database objects Find for different types of database objects all the prefixes that are used in different names. One should be consistent in naming, including in the use of prefixes. If you use prefix in the name of a database object, then it could refer to the type of the database object. Do not use different prefixes in the names of database objects that have the same type. General INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View