WITH user_defined_derived_tables AS (SELECT
views.table_schema,
views.table_name,
views.view_definition,
'VIEW' AS table_type
FROM
information_schema.views
WHERE 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)
UNION SELECT schemaname, matviewname, definition, 'MATERIALIZED VIEW' AS table_type
FROM pg_catalog.pg_matviews)
SELECT
Count(*) AS nr_of_derived_tables,
Count(*) FILTER (WHERE view_definition~*'((array|json|jsonb|json_object|jsonb_object|range|range_intersect|string)_|(json_array|xml))agg') AS nr_of_views_with_agg,
Count(*) FILTER (WHERE view_definition~*'((array|json|jsonb|json_object|jsonb_object|range|range_intersect|string)_|(json_array|xml))agg(?=.*GROUP BY[[:space:]]+BY[[:space:]]+)') AS nr_of_views_with_agg_group,
Count(*) FILTER (WHERE view_definition~*'(min|max|sum|avg|count)[(]') AS nr_of_views_with_stats,
Count(*) FILTER (WHERE view_definition~*'(min|max|sum|avg|count)[(](?=.*GROUP[[:space:]]+BY[[:space:]]+)') AS nr_of_views_with_stats_group,
Count(*) FILTER (WHERE view_definition~*'GROUP[[:space:]]+BY[[:space:]]+') AS nr_of_views_with_group
FROM user_defined_derived_tables;
Collections
This query belongs to the following collections:
Name
Description
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
Derived tables
Queries of this category provide information about the derived tables (views, materialized views), which are used to implement virtual data layer.