NAME

DBIO::PostgreSQL::Diff::NoStatement - An operation the diff has no statement for is refused, not written as a comment or a placeholder

VERSION

version 0.900007

SYNOPSIS

use DBIO::PostgreSQL::Diff::NoStatement ();

# in the diff method of an operation class, before the operation is built
DBIO::PostgreSQL::Diff::NoStatement->refuse_without_definition(
  kind           => 'trigger',
  name           => "$trigger_name on $table_key",
  in_database    => $in_database,
  from           => 'pg_get_triggerdef',
  null_when_gone => 1,
) unless ($target_entry->{definition} // '') =~ /\S/;

# in as_sql, where the operation has no statement
DBIO::PostgreSQL::Diff::NoStatement->throw(
  $self, "trigger $trigger_name on $table_key", 'its trigger_info has no definition',
);

# and behind the last action as_sql knows
DBIO::PostgreSQL::Diff::NoStatement->throw($self, "trigger $trigger_name on $table_key");

DESCRIPTION

A function, a trigger, an index and a view are not written by DBIO::PostgreSQL::Diff from their parts: they are written, and compared, as the text the catalog gives for them (pg_get_functiondef, pg_get_triggerdef, pg_get_indexdef, pg_get_viewdef). A model that has such an object without that text leaves the diff with an operation and no statement.

What used to come out then was a stand-in: -- CREATE TRIGGER ... (definition unavailable), or CREATE INDEX ... (?), or for an index that had its columns in the model the plain index on those columns. None of the three is an answer:

  • The comment is not a statement that does nothing. "_execute_ddl" in DBIO::Deploy::Base cuts the script at its semicolons and skips every piece that starts with --. A comment has no semicolon, so it is one piece with the statement that follows it, and that statement is skipped as well. A trigger whose definition changed was dropped and not created again.

  • (?) is not SQL.

  • The columns of an index are not the index. Whether it is unique, its predicate, its access method, the order and the operator class of each column are in the definition and nowhere else that a statement is written from.

The rule that answers this stands here, once:

An operation that has no statement is not built, and where it is built by hand it is not written. "refuse_without_definition" is for the diff method of an operation class -- refusing to diff: ..., see "WHAT IS REFUSED" in DBIO::PostgreSQL::Diff, so that it is "diff" in DBIO::PostgreSQL::Deploy that dies and not a later as_sql or apply. "throw" is for as_sql: an operation somebody built with new has passed no diff, and its as_sql dies instead of returning a comment, a placeholder, an empty string or nothing.

When the catalog has no definition

Measured on PostgreSQL 18.6: pg_get_functiondef, pg_get_triggerdef and pg_get_indexdef return NULL for an object that is not there when they are asked. They look it up apart from the snapshot of the statement that calls them, so a session that reads the catalog under an older snapshot (REPEATABLE READ) still finds the row of a function, a trigger or an index another session has dropped since -- with its name, and for an index with its columns, that it is unique and its predicate -- and gets no definition for it. That is the one way DBIO::PostgreSQL::Introspect was found to hand out such an entry; every function, trigger and index that was there had its definition. "refuse_without_definition" says so for these three (null_when_gone).

A view is no such case. pg_get_viewdef does not return NULL for a view that is gone, it raises could not open relation with OID ..., and the reading of the model dies of it. Nor is an aggregate: pg_get_functiondef raises an error for one, and DBIO::PostgreSQL::Introspect::Functions reads an aggregate and a window function without a definition. The diff refuses one it would have to create or change, with a message of its own ("diff" in DBIO::PostgreSQL::Diff::Function).

The other way to such a model is to build it by hand.

METHODS

refuse_without_definition

DBIO::PostgreSQL::Diff::NoStatement->refuse_without_definition(
  kind           => 'index',
  name           => 'users_email_idx on auth.users',
  in_database    => 0,
  from           => 'pg_get_indexdef',
  null_when_gone => 1,
  also           => 'Its columns are in the model, but ...',
);

Dies with the refusal for an object the diff would have to create, or create again, and that the target model has no definition for.

kind -- what the object is, as a reader calls it: function, trigger, index, view
name -- its name as a reader sees it, unquoted
in_database -- true when the source model has the object as well. The diff then cannot say whether the two are the same either: it compares them by their definitions.
from -- the catalog function the definition comes from
null_when_gone -- true when that function returns NULL for an object that is gone ("When the catalog has no definition"). The message then names that as the cause, and reading the model again as the way out.
also -- optional: a sentence more on why the diff cannot write the object from what the model does hold of it. It is a line of the message, or several with a newline between them.

throw

DBIO::PostgreSQL::Diff::NoStatement->throw($op, $object, $why);
DBIO::PostgreSQL::Diff::NoStatement->throw($op, $object);

Dies for an operation as_sql has no statement for. $op is the operation, $object says what it is on, as a reader calls it (function public.f()), and $why why there is no statement. Without $why the reason is that the class of $op does not know its action: every as_sql ends in this call, so that an action nobody wrote a statement for is not answered with nothing.

The message names the class of the operation, its action and the object.

SEE ALSO

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.