38002ERRORTier 2 — Caution✅ HIGH confidencemodifying SQL data not permitted
Category: External Routine ExceptionVersions: All Postgres versions
What this means
SQLSTATE 38002 is raised when an external routine declared as READS SQL DATA or CONTAINS SQL (read-only) attempts to execute a data-modifying statement.
Why it happens
- 1An external function declared with a read-only data access attribute executes INSERT, UPDATE, DELETE, or other data-modifying SQL
How to reproduce
Read-only external function attempting a write.
trigger — this will ERROR
ERROR: modifying SQL-data not permitted
Fix 1: Declare the external function as MODIFIES SQL DATA if it writes data
When the function needs to modify data.
fix
CREATE FUNCTION my_c_func() RETURNS VOID
AS 'my_extension', 'my_c_func'
LANGUAGE C
MODIFIES SQL DATA;Why this works
The MODIFIES SQL DATA attribute permits the function to execute write operations.
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 →