| Goal | This query identifies base table columns and domains that utilize CHECK constraints to simulate boolean logic on non-boolean data types. It targets constraints that restrict the domain of permitted values to binary sets, such as {0, 1}, {'Y', 'N'}, {'T', 'F'}, or string literals like 'true'/'false'. While functional, this "pseudo-boolean" pattern is considered suboptimal in PostgreSQL. The native BOOLEAN data type is preferred for its storage efficiency, semantic clarity, and built-in support for logical operators, rendering such manual constraints unnecessary. |
|---|---|
| Notes | Find base table columns that have not type BOOLEAN and have a CHECK constraint that refers to a possibility that the task of the column is to record Boolean values. For instance, the type of a column could be SMALLINT and the column has a CHECK constraint that determines that possible values in the column are 0 and 1. |
| Type | Problem detection Each row in the result could represent a flaw in the design |
| Reliability | Medium Medium number of false-positive results |
| License | MIT (opens in new tab) |
| Fixing Suggestion | Specify for each column a right data type that takes into account expected values in the column. Use Boolean type instead of emulating it based on some other data type. Change the type of the column to BOOLEAN. Drop the check constraints. |
| Data Source | INFORMATION_SCHEMA+system catalog |
| SQL Query |
|
Collections
This query belongs to the following collections:
Find problems automatically
Queries, that results point to problems in the database. Each query in the collection produces an initial assessment. However, a human reviewer has the final say as to whether there is a problem or not .
| Name | Description |
|---|---|
| Find problems automatically | Queries, that results point to problems in the database. Each query in the collection produces an initial assessment. However, a human reviewer has the final say as to whether there is a problem or not . |
Categories
This query is classified under the following categories:
Boolean data
Queries of this category provide information about truth-values data that is kept in the database.
CHECK constraints
Queries of this category provide information about CHECK constraints.
Data types
Queries of this category provide information about the data types and their usage.
Domains
Queries of this category provide information about reusable specifications of column properties.
Validity and completeness
Queries of this category provide information about whether database design represents the world (domain) correctly (validity) and whether database design captures all the information about the world (domain) that is correct and relevant (completeness).
| Name | Description |
|---|---|
| Boolean data | Queries of this category provide information about truth-values data that is kept in the database. |
| CHECK constraints | Queries of this category provide information about CHECK constraints. |
| Data types | Queries of this category provide information about the data types and their usage. |
| Domains | Queries of this category provide information about reusable specifications of column properties. |
| Validity and completeness | Queries of this category provide information about whether database design represents the world (domain) correctly (validity) and whether database design captures all the information about the world (domain) that is correct and relevant (completeness). |