42P13ERRORTier 2 — Caution✅ HIGH confidenceinvalid function definition
Category: Syntax Error or Access Rule ViolationVersions: All Postgres versions
What this means
SQLSTATE 42P13 is raised when a CREATE FUNCTION or CREATE PROCEDURE statement contains an invalid combination of options — for example, a STRICT function declared as returning SETOF type, or conflicting function attributes.
Why it happens
- 1Contradictory or mutually exclusive function attributes in CREATE FUNCTION
- 2Return type incompatible with declared function behaviour (e.g., STRICT + SETOF in some contexts)
- 3Invalid SQL function body for the declared return type
How to reproduce
CREATE FUNCTION with contradictory attributes.
trigger — this will ERROR
CREATE FUNCTION bad_fn() RETURNS VOID
LANGUAGE SQL STRICT
AS $ SELECT 1 $; -- VOID function with STRICT is invalidERROR: invalid use of STRICT with VOID return type
Fix 1: Remove conflicting function attributes
When CREATE FUNCTION raises 42P13.
fix
CREATE FUNCTION good_fn(x INT) RETURNS INT
LANGUAGE SQL STRICT
AS $ SELECT x * 2 $;Why this works
Review function attributes for compatibility. STRICT is meaningful only for functions that receive input parameters and return a value.
Sources
📚 Official docs: https://www.postgresql.org/docs/current/errcodes-appendix.html
🔧 Source ref: Class 42 — Syntax Error or Access Rule Violation (Postgres-specific)
Confidence assessment
✅ HIGH confidence
Postgres-specific. Stable across versions.
See also
🔗 Related errors
📄 Reference pages
CREATE FUNCTIONFunction Attributes
⚙️ 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 →