Goal Find the derived tables (views and materialized views) that have a column with the xid type, i.e., these use the data from the hidden xmin column of a base table. If one uses optimistic approach for dealing with the concurrent data modifications, then xmin values should be presented by views and used in routines that modify or delete rows.
Notes In the returned body of subquery of view/materialized view the query replaces each newline character with the line break (br) tag for the better readability in case the query result is displayed in a web browser.
Type General (Overview of some aspect of the database.)
License MIT License
Data Source INFORMATION_SCHEMA+system catalog
SQL Query
SELECT 
table_schema, 
table_name,
column_name,
'VIEW' AS type,
regexp_replace(view_definition,'[\r\n]','
','g') AS view_definition FROM information_schema.views AS v INNER JOIN information_schema.columns AS c USING (table_schema, table_name) 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) AND c.data_type='xid' UNION SELECT nspname, relname, attname, 'MATERIALIZED VIEW' AS type, regexp_replace(pg_get_viewdef(pg_class.oid),'[\r\n]','
','g') AS view_definition FROM pg_class INNER JOIN pg_namespace ON pg_class.relnamespace=pg_namespace.oid INNER JOIN pg_attribute ON pg_class.oid=pg_attribute.attrelid INNER JOIN pg_type ON pg_attribute.atttypid=pg_type.oid WHERE relkind = 'm' AND attnum>=1 AND attisdropped='f' AND typname='xid' ORDER BY table_schema, table_name, type;
Collections

This query belongs to the following collections:

NameDescription
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

This query is classified under the following categories:

NameDescription
Concurrency controlQueries of this category provide information about concurrency control.
Derived tablesQueries of this category provide information about the derived tables (views, materialized views), which are used to implement virtual data layer.