38001
PostgreSQLERRORNotableExternal Routine ExceptionHIGH confidence

containing SQL not permitted

What this means

SQLSTATE 38001 is raised when an external routine (e.g., a C function) attempts to execute SQL in a context where SQL execution is not permitted.

Why it happens
  1. 1An external language function attempts to execute SQL when it is not allowed to do so in the current calling context
How to reproduce

External function executing SQL in a forbidden context.

expected output

ERROR:  containing SQL not permitted

Fix

Restructure the function to execute SQL in a permitted context

WHEN When this error appears from an external routine.

Why this works

Review where the function is called from and whether SQL execution is permitted in that context. Functions called during certain operator or aggregate processing may not be allowed to execute SQL.

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