unhandled exception in PL/pgSQL

SQLSTATE P0001 condition raise_exception class P0 — PL/pgSQL Error severity ERROR
Reproduced & verified on PostgreSQL 14.23, 15.18, 16.14, 17.10 and 18.4 — identical message on every version.
Last reviewed 11 Jun 2026 · Reproduced live with the SQL on this page.

Symptoms

A PL/pgSQL RAISE EXCEPTION fired with a custom message and the default SQLSTATE P0001 (raise_exception). This is the errors-new counterpart of the generic RAISE page.

What the server log shows

ERROR:  Insufficient balance for account 4021
CONTEXT:  PL/pgSQL function transfer_funds(integer,numeric) line 12 at RAISE

Why PostgreSQL raises this — what the manual says

Section 41.9.1 Reporting Errors and Messages:

“EXCEPTION raises an error (which normally aborts the current transaction); the other levels only generate messages of different priority levels.”

PL/pgSQL’s RAISE EXCEPTION signals application errors. Without USING ERRCODE or a condition name, PostgreSQL reports the custom text under P0001.

Common causes

How to fix it

  1. Read the message and CONTEXT to find the raising function/line.
  2. Fix the input/state that triggered the rule, or adjust the rule.
  3. Assign a specific SQLSTATE via RAISE … USING ERRCODE so callers can branch on it.

Related & next steps

Reference: PostgreSQL 18 Section 43.9 “Errors and Messages”.