42P13
PostgreSQLERRORNotableSyntax Error or Access Rule ViolationHIGH confidence

invalid function definition

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
  1. 1Contradictory or mutually exclusive function attributes in CREATE FUNCTION
  2. 2Return type incompatible with declared function behaviour (e.g., STRICT + SETOF in some contexts)
  3. 3Invalid SQL function body for the declared return type
How to reproduce

CREATE FUNCTION with contradictory attributes.

trigger — this will error
trigger — this will error
CREATE FUNCTION bad_fn() RETURNS VOID
LANGUAGE SQL STRICT
AS $ SELECT 1 $; -- VOID function with STRICT is invalid

expected output

ERROR:  invalid use of STRICT with VOID return type

Fix

Remove conflicting function attributes

WHEN When CREATE FUNCTION raises 42P13.

Remove conflicting function attributes
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 documentation ↗

Class 42 — Syntax Error or Access Rule Violation (Postgres-specific)

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All PostgreSQL errors