PG
PRO
39P03ERRORTier 2 — Caution✅ HIGH confidence

event trigger protocol violated

Category: External Routine Invocation ExceptionVersions: Postgres 9.3+

What this means

SQLSTATE 39P03 is a Postgres-specific error raised when an event trigger function violates the event trigger calling protocol — for example, returning a non-VOID value from an event trigger function.

Why it happens

  1. 1An event trigger function returns a non-VOID value (event triggers must return VOID)
  2. 2An event trigger function does not follow the event trigger calling conventions

How to reproduce

Event trigger function returning a non-VOID value.

trigger — this will ERROR
CREATE OR REPLACE FUNCTION bad_event_trigger() RETURNS event_trigger AS $
BEGIN
  -- implementation
END;
$ LANGUAGE plpgsql;
-- If it returns a value instead of nothing, 39P03 fires
ERROR: event trigger protocol violated

Fix 1: Ensure event trigger functions return VOID

When writing event trigger functions.

fix
CREATE OR REPLACE FUNCTION ddl_event_fn() RETURNS event_trigger AS $
DECLARE obj RECORD;
BEGIN
  FOR obj IN SELECT * FROM pg_event_trigger_ddl_commands() LOOP
    RAISE NOTICE 'DDL: % on %', obj.command_tag, obj.object_identity;
  END LOOP;
  -- no RETURN value needed
END;
$ LANGUAGE plpgsql;

Why this works

Event trigger functions declared as RETURNS event_trigger must not return a value. The function must complete normally (RETURN; implicitly) or by falling off the end.

Version notes

Postgres 9.3+Event triggers introduced in Postgres 9.3.

Sources

📚 Official docs: https://www.postgresql.org/docs/current/errcodes-appendix.html

📚 Feature docs: https://www.postgresql.org/docs/current/event-trigger-definition.html

🔧 Source ref: Class 39 — External Routine Invocation Exception (Postgres-specific)

Confidence assessment

✅ HIGH confidence

Postgres-specific. Stable since 9.3.

See also

📄 Reference pages

Event TriggersCREATE EVENT TRIGGER
⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →