↑↓ 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

Reading PG 18current·documented in 22 of 22 versions, 8.1 to 20

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.

Source: src/backend/utils/errcodes.txt

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.

Source: src/backend/commands/trigger.c

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.

Source: contrib/tcn/tcn.c

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.

Source: src/pl/plperl/plperl.c

Message templates

ERROR · message.trigger-null

Primary

trigger function %u returned null value

Source: src/backend/commands/trigger.c

ERROR · message.before-statement

Primary

BEFORE STATEMENT trigger cannot return a value

Source: src/backend/commands/trigger.c

ERROR · message.tcn-called-as-trigger

Primary

triggered_change_notification: must be called as trigger

Source: contrib/tcn/tcn.c

ERROR · message.tcn-after-change

Primary

triggered_change_notification: must be called after the change

Source: contrib/tcn/tcn.c

ERROR · message.tcn-each-row

Primary

triggered_change_notification: must be called for each row

Source: contrib/tcn/tcn.c

ERROR · message.tcn-one-parameter

Primary

triggered_change_notification: must not be called with more than one parameter

Source: contrib/tcn/tcn.c

ERROR · message.tcn-primary-key

Primary

triggered_change_notification: must be called on a table with a primary key

Source: contrib/tcn/tcn.c

WARNING · message.plperl-delete-warning

Primary

ignoring modified row in DELETE trigger

Source: src/pl/plperl/plperl.c

ERROR · message.plperl-invalid-return

Primary

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

Source: src/pl/plperl/plperl.c

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:78c5cae4e0aa0c243deee6fbbae… · English manual source