PostgreSQL raises 2F005 when a PL/pgSQL function that is declared to return a value finishes without executing a RETURN statement.
function_executed_no_return_statement (PostgreSQL 2F005) appears when a PL/pgSQL function declared with RETURNS <type> exits without hitting a RETURN statement. Ensure every execution path ends with RETURN or change the function to RETURNS void to resolve the error.
function_executed_no_return_statement
PostgreSQL error code 2F005 signals that a PL/pgSQL function declared to return a value completed execution without issuing a RETURN. The server cannot supply the expected result, so it aborts the call and raises function_executed_no_return_statement.
The error is runtime, not syntax. It only appears when the problematic execution path is taken.
Catching it early is important because it can break application logic, stored procedure chains, and scheduled jobs.
A RETURN is missing in at least one code path of a non-void function.
This commonly happens after adding conditional branches, early EXIT statements, or TRY-CATCH blocks that swallow the RETURN.
The error also occurs when a RETURNS TABLE or RETURNS SETOF function forgets to RETURN NEXT or RETURN QUERY before the end.
Add an explicit RETURN at the end of the function or in every branch. If the function should not return anything, redefine it as RETURNS void.
Verify that exception handlers rethrow or return a default value.
Test all logical paths with representative input data.
If-ELSE chains: place a final ELSE with a RETURN or end the function with RETURN default_value.
Exception blocks: include RETURN inside EXCEPTION WHEN or add a final RETURN after END;
Use static analysis or pgTAP tests to assert that every path returns.
Keep functions short and single-responsibility so missing RETURNs are obvious.
Prefer RETURNS void for procedural code that produces side effects only. Review diff changes to ensure new branches include RETURN.
2F002 - modifying_sql_data_not_permitted triggers when a read-only function writes data. Change volatility or rewrite queries.
25114 - invalid_cursor_state arises when fetching from a closed cursor. Always OPEN before FETCH and CLOSE afterward.
.
Yes. SQL language functions declared RETURNS something must include a SELECT expression or RETURN QUERY. Omitting it triggers the same 2F005 error.
Yes. PostgreSQL sends SQLSTATE 2F005 over the wire, so drivers can trap it. However, fixing the function is the recommended approach.
Callers that expect a result set will break. Ensure no dependency exists or update the calling SQL before switching to void.
Galaxy’s editor flags missing RETURN statements during linting and lets teams review PL/pgSQL diffs collaboratively, preventing the error before deployment.