| Goal | Find Boolean expressions, queries, routines, and default values that refer to value 'NULL'. Perhaps NULL was intended instead. 'NULL' is a string (a value) but NULL is a special marker for denoting missing value. |
|---|---|
| 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 | In case of DEFAULT values - if NULL is the intention, then drop the default value because by default each SQL base table column that is not a part of the primary key is optional, i.e., permits NULLs. In case of other types of objects - use NULL instead of NULL. |
| Data Source | INFORMATION_SCHEMA+system catalog |
| SQL Query |
|
SQL statements that help generate fixes for the identified problem.
SELECT format('ALTER TABLE %1$I.%2$I ALTER COLUMN %3$I DROP DEFAULT;', A.table_schema, A.table_name, A.column_name) AS statements
FROM information_schema.columns A INNER JOIN information_schema.schemata S
ON A.table_schema=S.schema_name
WHERE lower(column_default)='''null''::character varying'
AND (A.table_schema = 'public'
OR S.schema_owner<>'postgres')
AND (A.table_schema, A.table_name) IN (SELECT table_schema, table_name
FROM information_schema.tables
WHERE table_type='BASE TABLE')
ORDER BY A.table_schema, A.table_name, A.column_name;Drop the default that is associated directly with the base table column.
SELECT format('ALTER DOMAIN %1$I.%2$I DROP DEFAULT;', D.domain_schema, D.domain_name) AS statements
FROM information_schema.domains D INNER JOIN information_schema.schemata S ON D.domain_schema=S.schema_name
WHERE lower(D.domain_default)='''null''::character varying'
AND (D.domain_schema = 'public'
OR S.schema_owner<>'postgres')
ORDER BY domain_schema, domain_name;Drop the default that is associated with the domain.
| SQL Query to Generate Fix | Description |
|---|---|
| Drop the default that is associated directly with the base table column. |
| Drop the default that is associated with the domain. |
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:
Comfortability of data management
Queries of this category provide information about the means that have been used to make the use or management of database more comfortable and thus, more efficient.
Default value
Queries of this catergory provide information about the use of default values.
Derived tables
Queries of this category provide information about the derived tables (views, materialized views), which are used to implement virtual data layer.
Missing data
Queries of this category provide information about missing data (NULLs) in a database.
Syntactics
Queries of this category provide information about syntactic mistakes.
User-defined routines
Queries of this category provide information about the user-defined routines
| Name | Description |
|---|---|
| Comfortability of data management | Queries of this category provide information about the means that have been used to make the use or management of database more comfortable and thus, more efficient. |
| Default value | Queries of this catergory provide information about the use of default values. |
| Derived tables | Queries of this category provide information about the derived tables (views, materialized views), which are used to implement virtual data layer. |
| Missing data | Queries of this category provide information about missing data (NULLs) in a database. |
| Syntactics | Queries of this category provide information about syntactic mistakes. |
| User-defined routines | Queries of this category provide information about the user-defined routines |
Further reading and related materials: