The list of all the queries

Number of derived tables that aggregate data

Query goal: Find the number of derived tables that aggregate data.
Query type: Sofware measure (Numeric values (software measures) about the database)
Query license: MIT License
Data source: INFORMATION_SCHEMA+system catalog
SQL query: Click on query to copy it

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 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 .
Find quick numeric overview of the databaseQueries that return numeric values showing mostly the number of different types of database objects in the database

Categories where the query belongs to

Category nameCategory description
Derived tablesQueries of this category provide information about the derived tables (views, materialized views), which are used to implement virtual data layer.

The list of all the queries