38000
PostgreSQLERRORNotableExternal Routine ExceptionHIGH confidence

external routine exception

What this means

SQLSTATE 38000 is the generic external routine exception code raised when an error occurs in a function or procedure written in an external programming language (C, PL/v8, PL/Python, PL/Perl, etc.) that does not map to a more specific 38xxx subcode.

Why it happens
  1. 1An unhandled exception in a C extension function, PL/Python, PL/Perl, or other external language function
How to reproduce

Error in a PL/Python function.

trigger — this will error
trigger — this will error
CREATE OR REPLACE FUNCTION bad_py() RETURNS VOID AS $
raise ValueError("something went wrong")
$ LANGUAGE plpython3u;

SELECT bad_py();

expected output

ERROR:  ValueError: something went wrong

Fix

Handle exceptions in the external language function

WHEN When a PL/Python, PL/Perl, or C extension function raises 38000.

Why this works

Add try/except (Python), eval{} (Perl), or PG_TRY/PG_CATCH (C) to handle errors gracefully within the function body and raise a Postgres error with a meaningful SQLSTATE.

Sources
Official documentation ↗

Class 38 — External Routine Exception

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All PostgreSQL errors