Query goal: | There must be at least n (one in this case) user-defined domains in the database each of that must be used in case of at least two columns of base tables. |
Notes about the query: | This query implements a requirement that might occur in a learning situation. The condition in the query ensures that if the requirement is not fulfilled, then the query returns one row, otherwise it does not return a row. The result is achieved by using a PostgreSQL feature that permits SELECT statements without the FROM clause. The number of domains (one in this case) serves here as an example. It could be replaced with some other threshold. |
Query type: | Problem detection (Each row in the result could represent a flaw in the design) |
Query reliability: | High (Few or no false-positive results) |
Query license: | MIT License |
Fixing suggestion: | Create additional domains and use these to define columns of base tables. |
Data source: | INFORMATION_SCHEMA only |
SQL query: | Click on query to copy it
WITH domains AS (SELECT domain_schema, domain_name FROM Information_schema.domains AS d WHERE domain_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 (SELECT Count(*) FROM Information_schema.columns AS c INNER JOIN Information_schema.tables AS t USING (table_schema, table_name) WHERE d.domain_schema=c.domain_schema AND d.domain_name=c.domain_name AND t.table_type='BASE TABLE')>=2) SELECT 'Too few domains that are used in case of at least two columns of base tables, must be at least one' As comment, (SELECT Count(*) AS cnt FROM domains) AS number_of_domains WHERE (SELECT Count(*) AS cnt FROM domains)<1; |
Collection name | Collection 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 . |
Category name | Category description |
---|---|
Assessment | Queries of this category could be used specifically in the learning environment to assess as to whether student projects have filled certain criteria. |
Comfortability of database evolution | Queries of this category provide information about the means that influence database evolution. |
Domains | Queries of this category provide information about reusable specifications of column properties. |