Goal There must be at least n (two in this case) user-defined foreign tables in the database.
Notes 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 foreign tables (two in this case) serves here as an example. It could be replaced with some other threshold.
Type Problem detection (Each row in the result could represent a flaw in the design)
Reliability High (Few or no false-positive results)
License MIT License
Data Source INFORMATION_SCHEMA only
SQL Query
WITH foreign_tables AS (SELECT foreign_table_schema, foreign_table_name
FROM information_schema.foreign_tables
WHERE foreign_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))
SELECT 'Too few foreign tables, must be at least one (two if you make your project based on the workbook)' As comment, (SELECT Count(*) AS cnt FROM foreign_tables) AS number_of_foreign_tables
WHERE (SELECT Count(*) AS cnt FROM foreign_tables)<2;

Collections

This query belongs to the following collections:

NameDescription
Find problems automaticallyQueries, 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:

NameDescription
AssessmentQueries of this category could be used specifically in the learning environment to assess as to whether student projects have filled certain criteria.
Distributed databaseQueries of this category provide information about the foreign table mechanism.