The list of all the queries

Base tables created based on a type

Query goal: Find base tables that have been created based on a composite type and thnk through as to whether it was really needed.
Query type: General (Overview of some aspect of the database.)
Query license: MIT License
Data source: system catalog only
SQL query: Click on query to copy it

SELECT n.nspname AS table_schema,
c.relname AS table_name,
n_type.nspname AS type_schema,
t.typname AS type_name,
(SELECT string_agg(attname || ' ' || typname, ', ' ORDER BY attnum) AS table_structure
FROM pg_attribute INNER JOIN pg_type ON pg_attribute.atttypid=pg_type.oid
WHERE pg_attribute.attrelid=c.oid
AND pg_attribute.attisdropped='f'
AND pg_attribute.attnum>0) AS type_structure
FROM pg_class AS c INNER JOIN pg_namespace AS n ON n.oid=c.relnamespace
INNER JOIN pg_authid AS a ON n.nspowner=a.oid
INNER JOIN pg_type AS t ON c.reloftype=t.oid
INNER JOIN pg_namespace AS n_type ON n_type.oid=t.typnamespace
WHERE (n.nspname='public' OR rolname<>'postgres')
AND c.reloftype<>0
AND c.relkind='r'
ORDER BY table_schema, table_name;

Collections where the query belongs to

Collection nameCollection description
Find problems by overviewQueries 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 .

Categories where the query belongs to

Category nameCategory description
Data typesQueries of this category provide information about the data types and their usage.
User-defined typesQueries of this category provide information about user-defined types in the database.

The list of all the queries