SQLSTATE 2F005Severity mediumLab verified

Incident brief

Function ended without RETURN

A function declared to return a value must execute a RETURN on every path; a code path that falls off the end without RETURN raises this SQL-routine exception at call time.

Reproduced on PostgreSQL 18.4Verified 2026-07-24 (isolated lab, PostgreSQL 18.4)Reviewed by Verified against PostgreSQL 18.4 in an isolated lab environment

In 10 seconds

What
Function ended without RETURN
What triggers it
Call a value-returning function whose control flow can reach the end without executing RETURN.
The fix
Ensure every path executes RETURN (add a final RETURN or cover all branches).
Proof
Reproduced on PostgreSQL 18.4 → A function call reproduces SQLSTATE 2F005; a path that reaches the end without RETURN fails, naming the function in the CONTEXT.

The fix

What to do right now

The immediate, application-level response to this error.

  • Ensure every path executes RETURN (add a final RETURN or cover all branches).
  • For functions that may legitimately produce nothing, RETURN NULL explicitly.
Fix — SQL
-- Ensure every path returns a value.
SELECT compute_total_fixed();

Related & next steps

Follow the thread

Everything this error touches — jump straight to the sibling error, term, runbook, or parameter.

Verification

PG 18.4
Last verified
2026-07-24 (isolated lab, PostgreSQL 18.4)
Reviewed by
Verified against PostgreSQL 18.4 in an isolated lab environment
Audit status
reviewed