Query goal: | What is the percentage of optional columns (that permit NULLs) in case of each base table? It is better to prohibit the use of NULLs in as many columns as possible. Otherwise the results of queries may be misleading. |
Notes about the query: | The query does not take into account system (hidden) columns like xmin. If a table has now columns, then the main query does not return any row about the table and thus there will not be division by zero. |
Query type: | Sofware measure (Numeric values (software measures) about the database) |
Query license: | MIT License |
Data source: | INFORMATION_SCHEMA only |
SQL query: | Click on query to copy it
SELECT C.table_schema, C.table_name, Round((SELECT Count(*) FROM information_schema.Columns AS C1 WHERE C1.is_nullable='YES' AND C1.table_schema=C.table_schema AND C1.table_name=C.table_name)::decimal*100/Count(C.column_name)::decimal,2) AS percentage_of_optional FROM information_schema.columns C INNER JOIN information_schema.tables T USING (table_schema, table_name) INNER JOIN information_schema.schemata S ON T.table_schema = S.schema_name WHERE T.table_type = 'BASE TABLE' AND (T.table_schema = 'public' OR S.schema_owner<>'postgres') GROUP BY C.table_schema, C.table_name ORDER BY percentage_of_optional DESC, C.table_schema, C.table_name; |
Collection name | Collection description |
---|---|
Find problems by overview | Queries that results point to different aspects of database that might have problems. A human reviewer has to decide based on the results as to whether there are problems or not . |
Find quick numeric overview of the database | Queries that return numeric values showing mostly the number of different types of database objects in the database |
Category name | Category description |
---|---|
Missing data | Queries of this category provide information about missing data (NULLs) in a database. |
Reference |
---|
https://www.lucidchart.com/techblog/2015/08/31/the-worst-mistake-of-computer-science/ |
http://www.dbdebunk.com/2017/04/null-value-is-contradiction-in-terms.html |