NAME
DBIO::PostgreSQL::Diff::Function - Diff operations for PostgreSQL functions
VERSION
version 0.900007
DESCRIPTION
Represents a function-level diff operation: CREATE FUNCTION, DROP FUNCTION, or CREATE OR REPLACE FUNCTION (when the definition has changed). Function identity is by the full signature key schema.name(identity_args).
ATTRIBUTES
function_key
The function's identity string: schema.name(args).
function_info
Function metadata hashref (definition, language, return_type, etc.).
replaced
True on the drop of a routine that is dropped only to be created again under the other kind: a function that is now a procedure, or the other way round. It tells DBIO::PostgreSQL::Diff to leave the two together instead of moving the drop to the removals ("ORDER OF OPERATIONS" in DBIO::PostgreSQL::Diff).
METHODS
diff
my @ops = DBIO::PostgreSQL::Diff::Function->diff($source, $target);
Compares function hashrefs by identity key. Produces create, replace (definition changed), or drop operations.
A function that is a procedure in the target (or the other way round) is not replaced: CREATE OR REPLACE cannot change the kind of a routine, and the server answers cannot change routine kind. The old routine is dropped (replaced true) and the new one created behind it. The identity arguments of a procedure carry the mode (f(IN integer)), a function's do not, so the two are filed under two keys; the diff pairs them by the signature with the mode left out. The DROP has no CASCADE: a routine something else depends on, a trigger for one, is refused by the server when the statement runs. That is so for a function a trigger or a column default still uses, a trigger function that becomes a procedure: the server answers cannot drop function ... because other objects depend on it, naming the trigger or the column, and the transaction apply runs the statements in leaves the database as it was (t/137-diff-function-kind-live.t).
Where the keys do not pair -- an INOUT argument (its mode is not left out of the signature), another argument name, an OUT argument one side has -- but the two routines have the same input_types, the diff is refused when the operations are built (refusing to diff: ...). PostgreSQL holds one routine per schema, name and input argument types, function or procedure, so the CREATE of the new one, written ahead of the removal of the old, would be answered function ... already exists with same argument types only when the statements run. The message names both routines and the way out, a DROP of the old one by hand and a new diff. (A model without input_types, one built by hand, is not checked.) Measured on PostgreSQL 18, in both directions: DROP then CREATE of the other kind runs for every case, so the refusal is the diff's rule, not the server's.
An aggregate or a window function (kind a or w, DBIO::PostgreSQL::Introspect::Functions) has no definition in the model: pg_get_functiondef raises an error for one, and the diff does not make a CREATE AGGREGATE up from pg_aggregate. One the target has and the database has not, or has with another definition (compared by the fingerprint of its catalog rows), or as another kind, is refused with refusing to diff: ..., naming it and saying to create or change it by hand. One that is the same on both sides is no operation, and one only the database has is dropped like any function: an aggregate by DROP AGGREGATE schema.name(args) (name(*) for one without arguments), a window function by DROP FUNCTION, in the removals. Dropping needs no definition, only the signature. What belongs to an extension is not in the model and is never dropped.
A function to create or to replace that the target model has no definition for is refused, with refusing to diff: ... and no statement (DBIO::PostgreSQL::Diff::NoStatement): the definition is all the diff writes a function from, and all it compares one by. pg_get_functiondef gives none for a function another session dropped while the model was read. A function only the source lacks the definition of is replaced like any other whose definition differs, and a drop needs none.
as_sql
Returns the SQL. For create and replace, emits the full function definition from introspection (pg_get_functiondef, the server's own text). For drop, returns DROP FUNCTION schema.name(identity_args);, DROP AGGREGATE ... for an aggregate (kind a; name(*) without arguments), or DROP PROCEDURE ... for a procedure -- an entry whose kind is p (DBIO::PostgreSQL::Introspect::Functions). PostgreSQL drops a procedure with no other statement (... is not a function). An entry that does not say what it is is dropped as a function.
The dropped function is written from the schema_name, function_name and identity_args of its function_info: schema and name each quoted for itself by the server's rule ("quote_ident" in DBIO::PostgreSQL::Util), the argument list as pg_get_function_identity_arguments gives it. It is not written from "function_key", which is where the model files the function. A function_info without the names falls back to the key, read as schema.name(args) with the schema ending at the first dot.
A create or replace whose function_info has no definition has no statement, and neither has an action this class does not know: as_sql dies ("throw" in DBIO::PostgreSQL::Diff::NoStatement) and returns no comment in its place. "diff" builds no such operation; one built by hand can be.
summary
Returns a one-line description such as +function: auth.update_modified_at().
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.