2F005ERRORTier 2 — Caution✅ HIGH confidencefunction executed in wrong section of rule
Category: SQL Routine ExceptionVersions: All Postgres versions
What this means
SQLSTATE 2F005 is raised when a function is called from a section of a rule where it is not permitted to execute — for example, calling a data-modifying function from the condition section of a rule.
Why it happens
- 1A rule condition or action contains a function call that is not allowed in that rule section
How to reproduce
Rule action calling a prohibited function.
trigger — this will ERROR
ERROR: function executed in wrong section of rule
Fix 1: Move the function call to a permitted section of the rule or use triggers instead
When this error appears in a rule definition.
fix
Why this works
Review the rule to ensure function calls are placed in appropriate sections. Consider using triggers (which have clearer execution semantics) instead of rules for complex logic.
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. Rarely encountered in practice; rules are uncommon in modern Postgres usage.
See also
🔗 Related errors
📄 Reference pages
RulesTriggersCREATE RULE
⚙️ 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 →