PG
PRO
38003ERRORTier 2 — Caution✅ HIGH confidence

prohibited SQL statement attempted

Category: External Routine ExceptionVersions: All Postgres versions

What this means

SQLSTATE 38003 is raised when an external routine attempts to execute a statement that is prohibited in its declared data access category — for example, a NO SQL external function containing any SQL statement.

Why it happens

  1. 1An external function declared NO SQL executes a SQL statement

How to reproduce

NO SQL external function executing SQL.

trigger — this will ERROR
ERROR: prohibited statement attempted

Fix 1: Match the function data access attribute to its actual SQL usage

When the external function data access attribute is misconfigured.

fix
CREATE FUNCTION my_fn() RETURNS VOID
AS 'my_ext', 'my_fn'
LANGUAGE C
CONTAINS SQL; -- or READS SQL DATA / MODIFIES SQL DATA

Why this works

Set the correct data access attribute so the function is allowed to execute its SQL statements.

Sources

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

🔧 Source ref: Class 38 — External Routine Exception

Confidence assessment

✅ HIGH confidence

Standard SQLSTATE. Stable across versions.

See also

📄 Reference pages

External Language FunctionsCREATE FUNCTION
⚙️ 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 →