NAME

DBIO::PostgreSQL::Introspect::Tables - Introspect PostgreSQL tables

VERSION

version 0.900007

DESCRIPTION

Fetches PostgreSQL table (and view, materialized view, foreign table, and partitioned table) metadata from pg_catalog.pg_class. System schemas are excluded, and so are the relations an installed extension owns (a pg_depend row of deptype e) -- PostGIS's spatial_ref_sys and geometry_columns, for instance: CREATE EXTENSION / DROP EXTENSION own them, so they are not the schema's to create or drop. What hangs on such a relation -- columns, indexes, constraints, triggers, policies -- is left out by the other introspect helpers along with it.

METHODS

fetch

my $tables = DBIO::PostgreSQL::Introspect::Tables->fetch($dbh, $filter);

Returns a hashref keyed by schema.table. Each value is a hashref with keys: schema_name, table_name, oid, kind (pg relkind char), kind_label (human-readable), persistence, comment, rls_enabled, rls_forced, view_definition, depends_on, depends_on_columns, partition_of, inherits.

view_definition is what pg_get_viewdef gives for a view or a materialized view, and undef for everything else. It is read under an empty search_path, so every relation, function and type in it that is not in pg_catalog is written with its schema (FROM auth.users, never FROM users): the definition is the same text whatever search_path the session has, and means the same in every session it is run in. That holds in every model, with "qualified_names" in DBIO::PostgreSQL::Introspect or without. The session is afterwards what it was ("under_empty_search_path" in DBIO::PostgreSQL::Introspect).

depends_on is, for a view or a materialized view, the relations its definition reads: an ArrayRef of their keys, sorted, as PostgreSQL records them (the pg_depend rows of the view's rewrite rule in pg_rewrite). A relation is named there whether or not it is in this hashref -- one in a schema outside $filter, or one an extension owns, is not. For every other kind of relation it is an empty ArrayRef. DBIO::PostgreSQL::Diff::View orders views by it.

depends_on_columns is, for the same two kinds, the columns the definition reads of each of those relations: a HashRef from the key of the relation to an ArrayRef of column names, sorted -- the same pg_depend rows, which name the column (refobjsubid). A column in the WHERE or in a join is read as much as one in the select list. A relation the view reads as a whole row (SELECT t FROM t) is in depends_on and has no entry here: PostgreSQL records the relation then and none of its columns. For every other kind of relation it is an empty HashRef. DBIO::PostgreSQL::Diff::Column asks it before it changes the type of a column, which PostgreSQL refuses while a view reads it.

partition_of is the key of the partitioned table a partition belongs to, and undef for a relation that is no partition.

inherits is, for a table that inherits from others and is no partition (CREATE TABLE ... INHERITS (...), ALTER TABLE ... INHERIT), the keys of the tables it inherits from, an ArrayRef in the order PostgreSQL keeps them (pg_inherits.inhseqno). For every other relation, a partition among them, it is an empty ArrayRef. Which of its columns such a table defines itself is is_local in DBIO::PostgreSQL::Introspect::Columns.

AUTHOR

DBIO & DBIx::Class Authors

COPYRIGHT AND LICENSE

Copyright (C) 2026 DBIO Authors Portions Copyright (C) 2005-2025 DBIx::Class Authors Based on DBIx::Class, heavily modified.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.