PG
PRO
09000ERRORTier 2 — Caution✅ HIGH confidence

triggered action exception

Category: Triggered Action ExceptionVersions: All Postgres versions

What this means

SQLSTATE 09000 is raised when a trigger function fails or raises an unhandled exception. The error aborts the triggering statement and rolls back any changes made by the trigger.

Why it happens

  1. 1A trigger function raises an unhandled exception using RAISE EXCEPTION
  2. 2A trigger function calls a function that errors out
  3. 3Business rule validation in a trigger detects a violation

How to reproduce

An INSERT trigger enforcing a business rule rejects the row.

trigger — this will ERROR
CREATE OR REPLACE FUNCTION check_balance() RETURNS TRIGGER AS $
BEGIN
  IF NEW.balance < 0 THEN
    RAISE EXCEPTION 'Balance cannot be negative';
  END IF;
  RETURN NEW;
END;
$ LANGUAGE plpgsql;
ERROR: Balance cannot be negative

Fix 1: Handle the trigger exception in application code

When trigger rejections are expected business logic.

fix

Why this works

Catch the error in the application, inspect the message, and present a user-friendly error without retrying the invalid operation.

Fix 2: Use RAISE EXCEPTION with a custom SQLSTATE for precise catching

When the trigger violation needs to be distinguishable from other errors.

fix
RAISE EXCEPTION 'Balance cannot be negative' USING ERRCODE = 'P0001';

Why this works

A custom SQLSTATE lets the application layer catch trigger errors by code rather than by parsing the message string.

Sources

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

🔧 Source ref: Class 09 — Triggered Action Exception

📖 Further reading: Postgres Trigger Functions

Confidence assessment

✅ HIGH confidence

Standard SQLSTATE. Behaviour consistent across all versions.

See also

📄 Reference pages

CREATE TRIGGERPL/pgSQL Trigger Functions
⚙️ 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 →