PG
PRO
2F003ERRORTier 2 — Caution✅ HIGH confidence

prohibited SQL statement attempted

Category: SQL Routine ExceptionVersions: All Postgres versions

What this means

SQLSTATE 2F003 is raised when a SQL function attempts to execute a statement type that is prohibited by its declared data access category — for example, a NO SQL function containing any SQL statement.

Why it happens

  1. 1A SQL function declared NO SQL contains a SQL statement
  2. 2A SQL function executes a statement type not allowed by its data access declaration

How to reproduce

NO SQL function containing a SQL statement.

trigger — this will ERROR
ERROR: prohibited statement attempted in SQL function

Fix 1: Match the function data access attribute to the actual statements used

When function data access attributes and content are mismatched.

fix

Why this works

Use CONTAINS SQL for functions with SQL statements, READS SQL DATA for read-only SQL, MODIFIES SQL DATA for write SQL. NO SQL means the function has no SQL statements at all.

Sources

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

🔧 Source ref: Class 2F — SQL Routine Exception

Confidence assessment

✅ HIGH confidence

Standard SQLSTATE. Stable across versions.

See also

📄 Reference pages

CREATE FUNCTIONSQL Functions
⚙️ 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 →