WITH compensating AS (SELECT CASE WHEN confupdtype='a' THEN 'ON UPDATE NO ACTION'
WHEN confupdtype='r' THEN 'ON UPDATE RESTRICT'
WHEN confupdtype='c' THEN 'ON UPDATE CASCADE'
WHEN confupdtype='n' THEN 'ON UPDATE SET NULL'
WHEN confupdtype='d' THEN 'ON UPDATE SET DEFAULT' END AS compensating_action
FROM pg_constraint AS o INNER JOIN pg_class AS c ON o.conrelid=c.oid
INNER JOIN pg_namespace AS np ON c.relnamespace=np.oid
INNER JOIN pg_authid AS a ON np.nspowner=a.oid
WHERE (np.nspname='public' OR rolname<>'postgres')
AND contype='f'
UNION ALL SELECT CASE WHEN confdeltype='a' THEN 'ON DELETE NO ACTION'
WHEN confdeltype='r' THEN 'ON DELETE RESTRICT'
WHEN confdeltype='c' THEN 'ON DELETE CASCADE'
WHEN confdeltype='n' THEN 'ON DELETE SET NULL'
WHEN confdeltype='d' THEN 'ON DELETE SET DEFAULT' END AS compensating_action
FROM pg_constraint AS o INNER JOIN pg_class AS c ON o.conrelid=c.oid
INNER JOIN pg_namespace AS np ON c.relnamespace=np.oid
INNER JOIN pg_authid AS a ON np.nspowner=a.oid
WHERE (np.nspname='public' OR rolname<>'postgres')
AND contype='f')
SELECT compensating_action, Count(*) AS number_of_occurrences
FROM compensating
GROUP BY compensating_action
ORDER BY compensating_action;
Collections
This query belongs to the following collections:
Name
Description
Find problems about integrity constraints
A selection of queries that return information about the state of integrity constraints in the datadabase. Contains all the types of queries - problem detection, software measure, and general overview
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
Categories
This query is classified under the following categories:
Name
Description
Comfortability of data management
Queries of this category provide information about the means that have been used to make the use or management of database more comfortable and thus, more efficient.
Compensating actions
Queries of this category provide information about compensating actions of foreign key constraints.
Relationships between tables
Queries of this category provide information about how database tables are connected to each other and whether such connections have been explicitly defined and whether it has been done correctly.