select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

SQLSTATE / CLASS 39 · EXTERNAL ROUTINE INVOCATION EXCEPTION

trigger_protocol_violated

SQLSTATE
39P01
Condition name
trigger_protocol_violated
Class
External Routine Invocation Exception
Source macro
ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED
Evidence
Source path confirmed
Analysis & operational context

English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗

<h1>39P01</h1>

At a glance

39P01 is trigger_protocol_violated. Fixed PostgreSQL 18.6 paths cover the core trigger manager, contrib/tcn checks, and PL/Perl trigger return handling, with path-specific messages and severity.

Meaning

The code marks a trigger protocol mismatch. Core trigger-manager messages include trigger function %u returned null value and BEFORE STATEMENT trigger cannot return a value. contrib/tcn checks trigger timing, level, argument count, and primary-key setup; PL/Perl has a DELETE-row WARNING and a separate ERROR for an invalid trigger return.

Diagnosis

Use the exact message to identify the path. For the trigger manager, check the isnull flag and BEFORE STATEMENT return contract; for tcn, check AFTER timing, row level, argument count, and primary key; for PL/Perl, check whether the return is undef, SKIP, or MODIFY. The DELETE-row WARNING means a modification was ignored, while the invalid-return message is an ERROR.

Response

Correct the timing, level, event, arguments, or return value for the identified path. For PL/Perl, decide whether the ignored DELETE-row modification is acceptable before writing again; retry only after the contract is fixed and the original operation is known not to have completed.

Versions

The locked catalogue records this condition from 7.4 in the listed formal snapshots and 19beta3; fixed source coverage is PostgreSQL 18.6.

Sources

See the fixed trigger.c, tcn.c, and plperl.c paths alongside the structured evidence record.

Source evidence

Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.

39P01 is trigger_protocol_violated in Class 39.

Method: Read the fixed definition row.

src.errcodes.18.6

The core trigger manager reports this code when a trigger function sets the isnull flag, and for invalid BEFORE STATEMENT return values.

Method: Read each fixed trigger-manager context and its message.

src.path.trigger

contrib/tcn checks trigger invocation context, AFTER timing, row level, argument count, and primary-key setup with this code.

Method: Read the complete tcn checks around each report.

src.path.tcn

PL/Perl has a WARNING variant for an ignored DELETE-row modification and an ERROR variant for an invalid trigger return value.

Method: Compare ereport levels and exact messages.

src.path.plperl

Message templates

ERROR · message.trigger-null

Primary

trigger function %u returned null value
ERROR · message.before-statement

Primary

BEFORE STATEMENT trigger cannot return a value
ERROR · message.tcn-called-as-trigger

Primary

triggered_change_notification: must be called as trigger
ERROR · message.tcn-after-change

Primary

triggered_change_notification: must be called after the change
ERROR · message.tcn-each-row

Primary

triggered_change_notification: must be called for each row
ERROR · message.tcn-one-parameter

Primary

triggered_change_notification: must not be called with more than one parameter
ERROR · message.tcn-primary-key

Primary

triggered_change_notification: must be called on a table with a primary key
WARNING · message.plperl-delete-warning

Primary

ignoring modified row in DELETE trigger
ERROR · message.plperl-invalid-return

Primary

result of PL/Perl trigger function must be undef, "SKIP", or "MODIFY"

Reproduction & repair cases

No reproduction case is attached to this condition.

Recorded runtime evidence

No runtime observation is attached to this entry.

Definition snapshot: english-manuals:043c90ea7404f171f59d747ef8b… · English manual source