38002
PostgreSQLERRORNotableExternal Routine ExceptionHIGH confidence
modifying SQL data not permitted
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.
expected output
ERROR: modifying SQL-data not permitted
Fix
Declare the external function as MODIFIES SQL DATA if it writes data
WHEN When the function needs to modify data.
Declare the external function as MODIFIES SQL DATA if it writes data
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 documentation ↗
Class 38 — External Routine Exception
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev