NAME

DBIO::PostgreSQL::Introspect::Triggers - Introspect PostgreSQL triggers

VERSION

version 0.900007

DESCRIPTION

Fetches user-defined trigger metadata from pg_catalog.pg_trigger. Internal (constraint) triggers are excluded. Timing (BEFORE/AFTER/INSTEAD OF), event (INSERT/UPDATE/DELETE/TRUNCATE), and orientation (ROW/STATEMENT) are decoded from the tgtype bitmask. A trigger on a partitioned table is carried down to every partition by the server, as a copy with pg_trigger.tgparentid set; the copy goes with the parent's trigger and is left out of the model, a trigger a partition has by its own declaration is in it. Tables an installed extension owns are left out by DBIO::PostgreSQL::Introspect::Tables, and their triggers with them.

METHODS

fetch

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

Returns a hashref keyed by schema.table. Each value is a hashref keyed by trigger name. Each trigger entry has: schema_name and table_name (the table it is on, each name for itself -- the key cannot be taken apart again), trigger_name, definition (from pg_get_triggerdef), timing, event, orientation, enabled, depends_on_columns.

depends_on_columns is the columns the trigger is bound to: those of its WHEN condition and of UPDATE OF col, ..., a HashRef from the key of a relation to an ArrayRef of column names, sorted, from the pg_depend rows of the trigger ("column_reads" in DBIO::PostgreSQL::Introspect). It is empty for a trigger without either. What the trigger's function reads is not in it. PostgreSQL does not alter the type of such a column (cannot alter type of a column used in a trigger definition); DBIO::PostgreSQL::Diff::Column asks it before it changes one.

execute_call

my $call = DBIO::PostgreSQL::Introspect::Triggers->execute_call($row);

The function a trigger runs, written as the call of EXECUTE FUNCTION: name(arg, ...), each argument a string literal. It is built from the catalog columns of the trigger -- the function from pg_trigger.tgfoid (regprocedure, the name as the search_path finds it) and the arguments from pg_trigger.tgargs -- and never read out of the text of pg_get_triggerdef. $row has function_signature, argument_count and arguments_hex (tgargs as hex). The result is the execute key of a trigger entry.

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.