2F004
PostgreSQLERRORNotableSQL Routine ExceptionHIGH confidence
reading SQL data not permitted
What this means
SQLSTATE 2F004 is raised when a SQL function declared as NO SQL or CONTAINS SQL (without read data permission) attempts to execute a SELECT or other read statement.
Why it happens
- 1A SQL function with NO SQL or inappropriate data access attribute attempts to read data with a SELECT
How to reproduce
Function with NO SQL attempting a SELECT.
expected output
ERROR: reading SQL-data not permitted
Fix
Change the function attribute to READS SQL DATA or CONTAINS SQL
WHEN When the function needs to read data.
Change the function attribute to READS SQL DATA or CONTAINS SQL
CREATE OR REPLACE FUNCTION my_fn() RETURNS INT LANGUAGE SQL READS SQL DATA AS $ SELECT COUNT(*) FROM orders; $;
Why this works
READS SQL DATA permits SELECT statements in the function body.
Sources
Official documentation ↗
Class 2F — SQL Routine Exception
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev