Filter Queries

Found 1077 queries.

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

#221. Use invocation of a precise function instead of casting in a default value expression

INFORMATION_SCHEMA only

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

#222. Using an internal data type - name

INFORMATION_SCHEMA only

Find base table columns that use type name that is used in system catalog tables. It is not a problem if the column is meant for recording identifiers of database objects.

General License: MIT (opens in new tab)

#223. Very similar domain names

INFORMATION_SCHEMA only

This query identifies potential redundancy or ambiguity in the schema by detecting pairs of user-defined domain names with high textual similarity. It utilizes the Levenshtein distance algorithm to find name pairs that differ by fewer than two characters. Crucially, the query implements a filter to exclude pairs where the divergence is attributable solely to numerical digits. This heuristic prevents false positives for valid domain variations based on size or version (e.g., d_name_20 vs. d_name_50), focusing the analysis strictly on likely typographical errors or semantic duplicates.

Problem detection License: MIT (opens in new tab)

#224. Views with the WITH LOCAL CHECK OPTION constraint

INFORMATION_SCHEMA only

Find updatable views that have WITH LOCAL CHECK OPTION constraint. The predicate of a view is the conjunction of the predicates of its (directly and indirectly) underlying tables (both base tables and derived tables) as well as the predicate of the view itself. In case of using WITH LOCAL CHECK OPTION constraint "New rows are only checked against the conditions defined directly in the view itself. Any conditions defined on underlying base views are not checked (unless they also specify the CHECK OPTION)." (PostgreSQL manual) Thus, use instead WITH CASCADED CHECK option to instruct the system to check new rows against the entire predicate of the view.

Problem detection License: MIT (opens in new tab)

#225. A getter does not return a value

INFORMATION_SCHEMA+system catalog base tables

Find user-defined SQL and PL/pgSQL routines that do not return a value although the name suggest that it should return a value (starts with "get").

Problem detection License: MIT (opens in new tab)

#226. A large number of triggers

INFORMATION_SCHEMA+system catalog base tables

Show user-defined triggers if there are more than 9 different trigger routine bodies, i.e., different triggers on different tables that do the same thing count as one trigger.

General License: MIT (opens in new tab)

#227. All-caps comments on derived tables and routines

INFORMATION_SCHEMA+system catalog base tables

This query identifies comments on derived tables (views) and routines that are 50 characters or longer and written entirely in uppercase letters. Writing long comments exclusively in capital letters should be avoided, as it significantly reduces readability and is generally perceived as shouting in digital communication.

Problem detection License: MIT (opens in new tab)

#228. All covering indexes

INFORMATION_SCHEMA+system catalog base tables

Find all covering indexes, which include data from additional columns in leaf blocks.

General License: MIT (opens in new tab)

#229. All declaratively partitioned tables

INFORMATION_SCHEMA+system catalog base tables

Find partitioned tables that have been implemented by using the declarative approach. Declarative partitioning is implemented in PostgreSQL starting from PostgreSQL 10.

General License: MIT (opens in new tab)

#230. All derived tables that use joining tables

INFORMATION_SCHEMA+system catalog base tables

This query identifies complex derived tables (views and materialized views) that perform data integration operations. Specifically, it filters for views whose definition involves joining two or more distinct tables. This distinguishes non-trivial views—which encapsulate relationship logic and data aggregation—from simple projection views that merely mirror a single base table. The result highlights the core reporting and data integration layer of the schema.

General License: MIT (opens in new tab)

#231. All enumerated types

INFORMATION_SCHEMA+system catalog base tables

Find all enumerated types.

General License: MIT (opens in new tab)

#232. All gin indexes

INFORMATION_SCHEMA+system catalog base tables

Find indexes with less common access methods. Gin indexes are, for instance, used to speed up PostgreSQL's built in full text search.

General License: MIT (opens in new tab)

#233. All non-unique indexes

INFORMATION_SCHEMA+system catalog base tables

Find secondary indexes that have been created in the database.

General License: MIT (opens in new tab)

#234. All parameters with DEFAULT values

INFORMATION_SCHEMA+system catalog base tables

Find parameters of user-defined routines that have a default value.

General License: MIT (opens in new tab)

#235. All partial indexes

INFORMATION_SCHEMA+system catalog base tables

Find indexes to a subset of table rows.

General License: MIT (opens in new tab)

#236. All sequence generators

INFORMATION_SCHEMA+system catalog base tables

Find all sequence generators.

General License: MIT (opens in new tab)

#237. All short cycles (tables)

INFORMATION_SCHEMA+system catalog base tables

Find pairs of tables that have both a 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.

General License: MIT (opens in new tab)

#238. All table functions

INFORMATION_SCHEMA+system catalog base tables

Find all functions that return a set of rows.

General License: MIT (opens in new tab)

#239. All unique keys have at least one optional column

INFORMATION_SCHEMA+system catalog base tables

This query identifies base tables where every unique key (whether enforced by a UNIQUE constraint or a unique index) includes at least one optional (nullable) column. This is a critical design flaw because it allows rows to exist where the identifying values are partially or entirely missing. Furthermore, because standard SQL treats NULL as an unknown state rather than a distinct value, two NULLs are not considered equal. As a result, a standard UNIQUE constraint fails to prevent the insertion of multiple identical rows if they contain NULL values. The query exempts constraints that explicitly use the UNIQUE NULLS NOT DISTINCT clause, which safely treats NULLs as equal.

Problem detection License: MIT (opens in new tab)

#240. All user triggers that are associated with tables

INFORMATION_SCHEMA+system catalog base tables

Find user-defined triggers that react to data modifications in tables. Triggers should be used only for the tasks that cannot be achieved in a declarative manner, i.e., by declaring a constraint. Triggers of the same table with the same event_manipulation, action_timing, and action_orientation are sorted based on the trigger name. This is the order of execution of triggers.

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
221 Use invocation of a precise function instead of casting in a default value expression Be 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 detection INFORMATION_SCHEMA only MIT (opens in new tab) View
222 Using an internal data type - name Find base table columns that use type name that is used in system catalog tables. It is not a problem if the column is meant for recording identifiers of database objects. General INFORMATION_SCHEMA only MIT (opens in new tab) View
223 Very similar domain names This query identifies potential redundancy or ambiguity in the schema by detecting pairs of user-defined domain names with high textual similarity. It utilizes the Levenshtein distance algorithm to find name pairs that differ by fewer than two characters. Crucially, the query implements a filter to exclude pairs where the divergence is attributable solely to numerical digits. This heuristic prevents false positives for valid domain variations based on size or version (e.g., d_name_20 vs. d_name_50), focusing the analysis strictly on likely typographical errors or semantic duplicates. Problem detection INFORMATION_SCHEMA only MIT (opens in new tab) View
224 Views with the WITH LOCAL CHECK OPTION constraint Find updatable views that have WITH LOCAL CHECK OPTION constraint. The predicate of a view is the conjunction of the predicates of its (directly and indirectly) underlying tables (both base tables and derived tables) as well as the predicate of the view itself. In case of using WITH LOCAL CHECK OPTION constraint "New rows are only checked against the conditions defined directly in the view itself. Any conditions defined on underlying base views are not checked (unless they also specify the CHECK OPTION)." (PostgreSQL manual) Thus, use instead WITH CASCADED CHECK option to instruct the system to check new rows against the entire predicate of the view. Problem detection INFORMATION_SCHEMA only MIT (opens in new tab) View
225 A getter does not return a value Find user-defined SQL and PL/pgSQL routines that do not return a value although the name suggest that it should return a value (starts with "get"). Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
226 A large number of triggers Show user-defined triggers if there are more than 9 different trigger routine bodies, i.e., different triggers on different tables that do the same thing count as one trigger. General INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
227 All-caps comments on derived tables and routines This query identifies comments on derived tables (views) and routines that are 50 characters or longer and written entirely in uppercase letters. Writing long comments exclusively in capital letters should be avoided, as it significantly reduces readability and is generally perceived as shouting in digital communication. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
228 All covering indexes Find all covering indexes, which include data from additional columns in leaf blocks. General INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
229 All declaratively partitioned tables Find partitioned tables that have been implemented by using the declarative approach. Declarative partitioning is implemented in PostgreSQL starting from PostgreSQL 10. General INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
230 All derived tables that use joining tables This query identifies complex derived tables (views and materialized views) that perform data integration operations. Specifically, it filters for views whose definition involves joining two or more distinct tables. This distinguishes non-trivial views—which encapsulate relationship logic and data aggregation—from simple projection views that merely mirror a single base table. The result highlights the core reporting and data integration layer of the schema. General INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
231 All enumerated types Find all enumerated types. General INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
232 All gin indexes Find indexes with less common access methods. Gin indexes are, for instance, used to speed up PostgreSQL's built in full text search. General INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
233 All non-unique indexes Find secondary indexes that have been created in the database. General INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
234 All parameters with DEFAULT values Find parameters of user-defined routines that have a default value. General INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
235 All partial indexes Find indexes to a subset of table rows. General INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
236 All sequence generators Find all sequence generators. General INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
237 All short cycles (tables) Find pairs of tables that have both a 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. General INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
238 All table functions Find all functions that return a set of rows. General INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
239 All unique keys have at least one optional column This query identifies base tables where every unique key (whether enforced by a UNIQUE constraint or a unique index) includes at least one optional (nullable) column. This is a critical design flaw because it allows rows to exist where the identifying values are partially or entirely missing. Furthermore, because standard SQL treats NULL as an unknown state rather than a distinct value, two NULLs are not considered equal. As a result, a standard UNIQUE constraint fails to prevent the insertion of multiple identical rows if they contain NULL values. The query exempts constraints that explicitly use the UNIQUE NULLS NOT DISTINCT clause, which safely treats NULLs as equal. Problem detection INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View
240 All user triggers that are associated with tables Find user-defined triggers that react to data modifications in tables. Triggers should be used only for the tasks that cannot be achieved in a declarative manner, i.e., by declaring a constraint. Triggers of the same table with the same event_manipulation, action_timing, and action_orientation are sorted based on the trigger name. This is the order of execution of triggers. General INFORMATION_SCHEMA+system catalog base tables MIT (opens in new tab) View