Query goal: | Each column should have the most appropriate data type. Developers sometimes misuse BIGINT, INTEGER, TEXT or VARCHAR type in places where a type that permits smaller values would be more appropriate and semantically descriptive. |
Notes about the query: | Query returns also information about columns that properties have been specified through a domain. |
Query type: | General (Overview of some aspect of the database.) |
Query license: | MIT License |
Fixing suggestion: | Change the data type or field size. If the type was selected with a perspective that values in the column will become quite big over time, then consider adding a CHECK constraint that further limits the values in the column. |
Data source: | INFORMATION_SCHEMA only |
SQL query: | Click on query to copy it
SELECT table_schema, table_name, column_name, data_type FROM INFORMATION_SCHEMA.columns WHERE (data_type IN ('bigint', 'integer', 'text') OR (data_type='character varying' AND character_maximum_length IS NULL)) AND (table_schema, table_name) IN (SELECT table_schema, table_name FROM INFORMATION_SCHEMA.tables WHERE table_type='BASE TABLE') AND table_schema NOT IN (SELECT schema_name FROM INFORMATION_SCHEMA.schemata WHERE schema_name<>'public' AND schema_owner='postgres' AND schema_name IS NOT NULL) ORDER BY data_type, table_schema, table_name, ordinal_position; |
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 . |
Category name | Category description |
---|---|
Data types | Queries of this category provide information about the data types and their usage. |
Reference |
---|
https://stackoverflow.com/questions/29560016/how-to-add-a-length-constraint-to-a-text-field |