Filter Queries

Found 1077 queries.

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

#701. ROW level BEFORE triggers that do not return a row if a check succeeds

INFORMATION_SCHEMA+system catalog base tables

Find ROW level BEFORE triggers that check a condition based on other rows, raise an exception but do not return the row if the condition check succeeds, i.e., exception is not raised.

Problem detection License: MIT (opens in new tab)

#702. ROW level BEFORE UPDATE triggers that do not return the new row

INFORMATION_SCHEMA+system catalog base tables

Find row level BEFORE UPDATE triggers that do not return the new row version. Exclude triggers that raise WARNING/EXCEPTION.

Problem detection License: MIT (opens in new tab)

#703. Row level triggers that update or delete data

INFORMATION_SCHEMA+system catalog base tables

This query identifies row-level triggers that contain UPDATE or DELETE statements within their execution body. Embedding data modification logic directly within row-level triggers introduces implicit side effects that can complicate transaction management and debugging. Furthermore, this pattern significantly increases the risk of causing cascading trigger chains or infinite recursion loops, potentially degrading system performance and stability. Such logic should be carefully audited to ensure it is strictly necessary and correctly implemented.

Problem detection License: MIT (opens in new tab)

#704. Row-level triggers with RETURN NULL cancellation logic

INFORMATION_SCHEMA+system catalog base tables

This query identifies row-level BEFORE and INSTEAD OF triggers that explicitly RETURN NULL. In PostgreSQL's trigger execution model, this return value acts as a cancellation signal. For BEFORE triggers on tables, it aborts the operation for the current row, preventing the INSERT, UPDATE, or DELETE and suppressing subsequent triggers. For INSTEAD OF triggers on views, it signals that no modification was performed. While this behavior can be used for conditional logic (e.g., silently ignoring invalid rows), it presents a risk of unintended data loss or logic errors if used incorrectly. These triggers should be audited to ensure the cancellation behavior is intentional and correctly implemented.

General License: MIT (opens in new tab)

#705. search_path should not be between quotation marks

INFORMATION_SCHEMA+system catalog base tables

Write security definer functions securely. Give to the DBMS correctly information about the sequence of schemas that constitute the search path. You shouldn't write search path value between quotation marks or apostrophes. Thus, instead of writing SET search_path = "public, pg_temp"; or SET search_path = 'public, pg_temp'; you should write SET search_path = public, pg_temp;

Problem detection License: MIT (opens in new tab)

#706. SECURITY DEFINER procedures cannot end transactions

INFORMATION_SCHEMA+system catalog base tables

You cannot use COMMIT and ROLLBACK in a SECURITY DEFINER procedure. Procedures appeared in PostgreSQL 11.

Problem detection License: MIT (opens in new tab)

#707. SECURITY DEFINER routines vulnerable to pg_temp hijacking

INFORMATION_SCHEMA+system catalog base tables

This query identifies SECURITY DEFINER routines that are vulnerable to Trojan-horse attacks via the pg_temp schema. It flags routines that either do not explicitly set the search_path, or set it incorrectly (e.g., using improper quoting). To secure these privileged routines, pg_temp must be appended as the last entry in the search_path. Omitting the search_path is only safe if every database object within the routine is explicitly schema-qualified. The query correctly excludes routines defined with a SQL-standard body (introduced in PostgreSQL 14), as they resolve objects at parse time and do not require explicit search_path configurations.

Problem detection License: MIT (opens in new tab)

#708. SECURITY INVOKER routines that access data

INFORMATION_SCHEMA+system catalog base tables

Find SECURITY INVOKER routines that read rows from a table, add rows to a table, update rows in a table, or delete rows from a table. Better to have for these purposes SECURITY DEFINER routines, which make it possible to give to the users privileges to only execute routines without having rights to access their underlying tables.

Problem detection License: MIT (opens in new tab)

#709. SELECT * in a routine body

INFORMATION_SCHEMA+system catalog base tables

SELECT statement should list the columns not use SELECT * to return data from all the columns. Firstly, it ensures, that the query asks only data that is really needed by the routine. It means less data that the DBMS has to fetch and pass to the routine. It could also mean that the DBMS can answer to a query based on an index without reading table blocks. Secondly, it documents the data that is returned by the query. The query does not consider objects that are a part of an extension.

Problem detection License: MIT (opens in new tab)

#710. SET DEFAULT compensatory action is unsuitable

INFORMATION_SCHEMA+system catalog base tables

Find foreign keys with SET DEFAULT compensatory action where the foreign key column does not have a default value. Compensatory actions cannot make changes that violate integrity constraints in a database. SET DEFAULT means that there shoud be a default value at the foreign key column.

Problem detection License: MIT (opens in new tab)

#711. SET NULL compensatory action is unsuitable

INFORMATION_SCHEMA+system catalog base tables

Find foreign key constraints that use a SET NULL compensating action but a foreign key column is mandatory, i.e., does not permit NULLs. Compensatory actions cannot make changes that violate integrity constraints in a database. SET NULL cannot put NULL to a mandatory column (delete a foreign key value).

Problem detection License: MIT (opens in new tab)

#712. Set operations that do not remove duplicate rows in derived tables

INFORMATION_SCHEMA+system catalog base tables

Find derived tables (views and materialized views) that use a set theoretic operation (union, except or intersect) in a manner that does not remove duplicate rows and thus can produce a multiset not a set. Make sure that it is what is needed.

General License: MIT (opens in new tab)

#713. Short cycles (tables)

INFORMATION_SCHEMA+system catalog base tables

Find pairs of tables that have both a mandatory (NOT NULL) and not defrerrable foreign key that references to the other table. Such cycles can involve more than two tables but the query detects only cycles with two tables.

Problem detection License: MIT (opens in new tab)

#714. Simplify regex by combining alpha and digit classes

INFORMATION_SCHEMA+system catalog base tables

This query identifies regular expressions that can be simplified by consolidating separate character class references. It specifically targets patterns that explicitly match both alphabetic characters ([:alpha:]) and numeric digits ([:digit:], \d, or [0-9]) as separate components within a larger character set (e.g., [[:alpha:][:digit:]]). These distinct classes can be refactored into the single, more concise POSIX character class [:alnum:], which logically represents the union of both. Performing this simplification improves the readability and compactness of the regular expression without altering its behavior.

Problem detection License: MIT (opens in new tab)

#715. Single-column natural primary keys

INFORMATION_SCHEMA+system catalog base tables

This query identifies primary keys that consist of a single column and are not system-generated (i.e., they are not associated with a sequence or defined as IDENTITY columns). This pattern is characteristic of a natural primary key, where the key's value is derived from a real-world, user-defined attribute rather than an arbitrary surrogate value. Identifying these keys is crucial for auditing a data model's key strategy and understanding its reliance on meaningful, potentially mutable, business data for entity identification.

General License: MIT (opens in new tab)

#716. Small tables

INFORMATION_SCHEMA+system catalog base tables

Find tables that have one column or zero columns.

General License: MIT (opens in new tab)

#717. Snake_case violations detected by common suffixes

INFORMATION_SCHEMA+system catalog base tables

This query identifies database identifiers (columns, parameters, etc.) that likely violate the snake_case naming convention based on suffix analysis. It flags names ending with common temporal or attributional terms (date, time, by) where the suffix is not immediately preceded by an underscore. This pattern is highly indicative of camelCase (e.g., createdDate, updatedBy) or PascalCase usage. Adhering to snake_case (e.g., created_date, updated_by) is the recommended standard for SQL database schemas to ensure consistency and readability.

Problem detection License: MIT (opens in new tab)

#718. Some candidate key values cannot be used as foreign key values

INFORMATION_SCHEMA+system catalog base tables

Find foreign key constraints in case of which some candidate key values cannot be used as foreign key values. Primary key/unique columns and foreign key columns should have the same data type and field size. If, for instance, the primary key column has type INTEGER and foreign key column has type SMALLINT, then one cannot use all the primary key values as foreign key values.

Problem detection License: MIT (opens in new tab)

#719. Some CHECKS are associated with a domain and some with the base table columns that have the domain

INFORMATION_SCHEMA+system catalog base tables

Find cases where some CHECKS are associated with a domain and some with the base table columns that have the domain. Avoid duplication of code. Write as little code as possible. If possible, move things "before the brackets" so to say. In this case it means declaring CHECKS at the level of the domain and not at the level of base table columns.

Problem detection License: MIT (opens in new tab)

#720. Some data modification functions return a value and some not

INFORMATION_SCHEMA+system catalog base tables

Find as to whether there are data modification routines that return a value as well as data modification routines that do not return a value.

Problem detection 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
701 ROW level BEFORE triggers that do not return a row if a check succeeds Find ROW level BEFORE triggers that check a condition based on other rows, raise an exception but do not return the row if the condition check succeeds, i.e., exception is not raised. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
702 ROW level BEFORE UPDATE triggers that do not return the new row Find row level BEFORE UPDATE triggers that do not return the new row version. Exclude triggers that raise WARNING/EXCEPTION. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
703 Row level triggers that update or delete data This query identifies row-level triggers that contain UPDATE or DELETE statements within their execution body. Embedding data modification logic directly within row-level triggers introduces implicit side effects that can complicate transaction management and debugging. Furthermore, this pattern significantly increases the risk of causing cascading trigger chains or infinite recursion loops, potentially degrading system performance and stability. Such logic should be carefully audited to ensure it is strictly necessary and correctly implemented. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
704 Row-level triggers with RETURN NULL cancellation logic This query identifies row-level BEFORE and INSTEAD OF triggers that explicitly RETURN NULL. In PostgreSQL's trigger execution model, this return value acts as a cancellation signal. For BEFORE triggers on tables, it aborts the operation for the current row, preventing the INSERT, UPDATE, or DELETE and suppressing subsequent triggers. For INSTEAD OF triggers on views, it signals that no modification was performed. While this behavior can be used for conditional logic (e.g., silently ignoring invalid rows), it presents a risk of unintended data loss or logic errors if used incorrectly. These triggers should be audited to ensure the cancellation behavior is intentional and correctly implemented. General INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
705 search_path should not be between quotation marks Write security definer functions securely. Give to the DBMS correctly information about the sequence of schemas that constitute the search path. You shouldn't write search path value between quotation marks or apostrophes. Thus, instead of writing SET search_path = "public, pg_temp"; or SET search_path = 'public, pg_temp'; you should write SET search_path = public, pg_temp; Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
706 SECURITY DEFINER procedures cannot end transactions You cannot use COMMIT and ROLLBACK in a SECURITY DEFINER procedure. Procedures appeared in PostgreSQL 11. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
707 SECURITY DEFINER routines vulnerable to pg_temp hijacking This query identifies SECURITY DEFINER routines that are vulnerable to Trojan-horse attacks via the pg_temp schema. It flags routines that either do not explicitly set the search_path, or set it incorrectly (e.g., using improper quoting). To secure these privileged routines, pg_temp must be appended as the last entry in the search_path. Omitting the search_path is only safe if every database object within the routine is explicitly schema-qualified. The query correctly excludes routines defined with a SQL-standard body (introduced in PostgreSQL 14), as they resolve objects at parse time and do not require explicit search_path configurations. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
708 SECURITY INVOKER routines that access data Find SECURITY INVOKER routines that read rows from a table, add rows to a table, update rows in a table, or delete rows from a table. Better to have for these purposes SECURITY DEFINER routines, which make it possible to give to the users privileges to only execute routines without having rights to access their underlying tables. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
709 SELECT * in a routine body SELECT statement should list the columns not use SELECT * to return data from all the columns. Firstly, it ensures, that the query asks only data that is really needed by the routine. It means less data that the DBMS has to fetch and pass to the routine. It could also mean that the DBMS can answer to a query based on an index without reading table blocks. Secondly, it documents the data that is returned by the query. The query does not consider objects that are a part of an extension. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
710 SET DEFAULT compensatory action is unsuitable Find foreign keys with SET DEFAULT compensatory action where the foreign key column does not have a default value. Compensatory actions cannot make changes that violate integrity constraints in a database. SET DEFAULT means that there shoud be a default value at the foreign key column. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
711 SET NULL compensatory action is unsuitable Find foreign key constraints that use a SET NULL compensating action but a foreign key column is mandatory, i.e., does not permit NULLs. Compensatory actions cannot make changes that violate integrity constraints in a database. SET NULL cannot put NULL to a mandatory column (delete a foreign key value). Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
712 Set operations that do not remove duplicate rows in derived tables Find derived tables (views and materialized views) that use a set theoretic operation (union, except or intersect) in a manner that does not remove duplicate rows and thus can produce a multiset not a set. Make sure that it is what is needed. General INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
713 Short cycles (tables) Find pairs of tables that have both a mandatory (NOT NULL) and not defrerrable foreign key that references to the other table. Such cycles can involve more than two tables but the query detects only cycles with two tables. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
714 Simplify regex by combining alpha and digit classes This query identifies regular expressions that can be simplified by consolidating separate character class references. It specifically targets patterns that explicitly match both alphabetic characters ([:alpha:]) and numeric digits ([:digit:], \d, or [0-9]) as separate components within a larger character set (e.g., [[:alpha:][:digit:]]). These distinct classes can be refactored into the single, more concise POSIX character class [:alnum:], which logically represents the union of both. Performing this simplification improves the readability and compactness of the regular expression without altering its behavior. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
715 Single-column natural primary keys This query identifies primary keys that consist of a single column and are not system-generated (i.e., they are not associated with a sequence or defined as IDENTITY columns). This pattern is characteristic of a natural primary key, where the key's value is derived from a real-world, user-defined attribute rather than an arbitrary surrogate value. Identifying these keys is crucial for auditing a data model's key strategy and understanding its reliance on meaningful, potentially mutable, business data for entity identification. General INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
716 Small tables Find tables that have one column or zero columns. General INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
717 Snake_case violations detected by common suffixes This query identifies database identifiers (columns, parameters, etc.) that likely violate the snake_case naming convention based on suffix analysis. It flags names ending with common temporal or attributional terms (date, time, by) where the suffix is not immediately preceded by an underscore. This pattern is highly indicative of camelCase (e.g., createdDate, updatedBy) or PascalCase usage. Adhering to snake_case (e.g., created_date, updated_by) is the recommended standard for SQL database schemas to ensure consistency and readability. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
718 Some candidate key values cannot be used as foreign key values Find foreign key constraints in case of which some candidate key values cannot be used as foreign key values. Primary key/unique columns and foreign key columns should have the same data type and field size. If, for instance, the primary key column has type INTEGER and foreign key column has type SMALLINT, then one cannot use all the primary key values as foreign key values. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
719 Some CHECKS are associated with a domain and some with the base table columns that have the domain Find cases where some CHECKS are associated with a domain and some with the base table columns that have the domain. Avoid duplication of code. Write as little code as possible. If possible, move things "before the brackets" so to say. In this case it means declaring CHECKS at the level of the domain and not at the level of base table columns. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
720 Some data modification functions return a value and some not Find as to whether there are data modification routines that return a value as well as data modification routines that do not return a value. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View