# 39P02 — srf_protocol_violated

> Source-backed reference for PostgreSQL SQLSTATE 39P02.
---

# 39P02

## At a glance {#at-a-glance}

39P02 is `srf_protocol_violated`. The fixed executor path checks value-per-call and materialize set-returning-function contracts and reports the exact violated return mode.

<!-- BEGIN SQLSTATE FACTS: generated by scripts/generate.py; do not edit -->

| Field | Value |
| --- | --- |
| SQLSTATE | `39P02` |
| Condition | `srf_protocol_violated` |
| Status | `active` |
| Known present by | `7.4` |
| Locked snapshots | `9.0.23, 9.1.24, 9.2.24, 9.3.25, 9.4.26, 9.5.25, 9.6.24, 10.23, 11.22, 12.22, 13.23, 14.24, 15.19, 16.15, 17.11, 18.6, 19beta3` |
| Macros | `ERRCODE_E_R_I_E_SRF_PROTOCOL_VIOLATED` |
| Aliases | `—` |

<!-- source facts: data/errcodes/39P02.json -->
<!-- END SQLSTATE FACTS -->

## Meaning {#meaning}

The executor received a set-returning function state that violated the selected protocol: `table-function protocol for value-per-call mode was not followed`, `table-function protocol for materialize mode was not followed`, or `unrecognized table-function returnMode: %d`.

## Diagnosis {#diagnosis}

Inspect the C or extension function that sets ReturnSetInfo fields, especially returnMode, isDone, and returnSet. This is an SRF protocol issue, not a row-count result.

## Response {#response}

Repair the SRF value-per-call or materialize implementation and its ReturnSetInfo state; changing LIMIT or transaction policy does not repair the executor contract.

## Versions {#versions}

The locked catalogue records this condition from 7.4 in the listed formal snapshots and 19beta3; fixed source coverage is PostgreSQL 18.6.

## Related {#related}

[`39P01`](../39p01/), [`39P03`](../39p03/), [`2F002`](../2f002/)

## Sources {#sources}

See the fixed [execSRF.c](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/executor/execSRF.c#L363-L381) and materialize path (lines 665-686) alongside the structured [evidence record](../data/evidence/39p02.json).
