Query goal: | Find default values that return current timestamp with the maximum number of fractional seconds (6). |
Query type: | Problem detection (Each row in the result could represent a flaw in the design) |
Query reliability: | Low (Many false-positive results) |
Query license: | MIT License |
Fixing suggestion: | If you do not need fractional seconds or do not need the maximum number of fractional seconds, then do not use function now() and invoke functions LOCALTIMESTAMP, CURRENT_TIMESTAMP, LOCALTIME, and CURRENT_TIME with an argument that determines the fractional seconds precision (for instance, LOCALTIMESTAMP(0)). |
Data source: | INFORMATION_SCHEMA only |
SQL query: | Click on query to copy it
WITH all_defaults AS (SELECT c.table_schema, c.table_name, c.column_name, c.data_type, c.domain_schema, c.domain_name, coalesce(c.column_default, domain_default) AS default_value, CASE WHEN c.column_default IS NOT NULL THEN 'Column default' ELSE 'Domain default' END AS default_type FROM information_schema.columns AS c LEFT JOIN information_schema.domains d USING (domain_schema, domain_name) WHERE c.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) AND (column_default IS NOT NULL OR domain_default IS NOT NULL)) SELECT table_schema, table_name, column_name, data_type, domain_schema, domain_name, default_value, default_type FROM all_defaults WHERE default_value~*'(localtimestamp|current_timestamp|localtime|current_time|now[(][)])$' ORDER BY table_schema, table_name, column_name; |
Collection name | Collection description |
---|---|
Find problems about base tables | A selection of queries that return information about the data types, field sizes, default values as well as general structure of base tables. Contains all the types of queries - problem detection, software measure, and general overview |
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 . |
Category name | Category description |
---|---|
Default value | Queries of this catergory provide information about the use of default values. |
Temporal data | Queries of this category provide information about temporal (time-related) data that is kept in the database. |
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). |