SQLSTATE P0000 ERROR Class P0: PL/pgSQL Error

plpgsql_error Plpgsql Error — SQLSTATE P0000

SQLSTATE P0000 (plpgsql_error): A PL/pgSQL runtime condition was raised.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

Symptoms

The server reports SQLSTATE P0000 (plpgsql_error), a condition in the PL/pgSQL Error class.

  • The error is written to the server log and returned to the client carrying SQLSTATE P0000.
  • Any driver (libpq, JDBC, psycopg, npgsql, pgx) surfaces this code in its error object so you can branch on it programmatically.
  • PL/pgSQL can trap it by name: EXCEPTION WHEN plpgsql_error THEN.

Environment

Severity: ERROR  |  PostgreSQL versions: 12, 13, 14, 15, 16, 17

Reproduce with the exact statement and read the full message in the server log (raise log_min_messages / set log_min_error_statement for more context).

Root Cause

P0000 belongs to Class P0 — PL/pgSQL Error. In this class, a PL/pgSQL runtime condition was raised.

The first two characters (P0) identify the error class, so application code can match the whole class via P0000 when the specific code is not needed.

Diagnostic Queries

Recovery

Handle it in the function: read RAISE messages, use INTO STRICT only when exactly one row is guaranteed, and add EXCEPTION handlers for expected conditions.

Reference: PostgreSQL error codes — Class P0 (PL/pgSQL Error).

Was this helpful?