↑↓ 选择↵ 打开⌫ 切换范围完整搜索

PG.CENTER 连接 PostgreSQL 文档、百科与生态知识。由 Pigsty 维护。

Wiki / SQLSTATE

39P02 — srf_protocol_violated

集合返回函数违反了 SRF 调用协议。

英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。

当前阅读 PG 18·选择有来源记录的版本

aliases
未知
class name
External Routine Invocation Exception
condition name
srf_protocol_violated
lang
en
sqlstate
39P02

版本定义 PG 18

39P02

速览 {#at-a-glance}

39P02 是 srf_protocol_violated。固定 executor 源码确认它检查 set-returning function 的 value-per-call、materialize 以及 returnMode 契约。

含义 {#meaning}

SQL 执行器收到的 ReturnSetInfo 状态与函数声明/实现不一致时,会报告此条件:报文可能是 table-function protocol for value-per-call mode was not followed、table-function protocol for materialize mode was not followed 或 unrecognized table-function returnMode: %d。它描述 SRF 协议,不是普通 SELECT 的行数结果。

诊断 {#diagnosis}

从完整消息判断是哪一类模式,再检查扩展或 C 函数如何设置 rsinfo.returnMode、isDone、returnSet 以及结果存储。优先定位提供该 set-returning function 的函数体和部署版本;不要把客户端收到的空结果误判成 39P02。

处置 {#response}

修正 SRF 实现以遵守所选 value-per-call 或 materialize 协议,并重新验证其 ReturnSetInfo 字段与返回声明。修复函数契约后再重试调用;仅改变 SQL 的 LIMIT、事务或客户端重试策略不能修复该 executor 协议错误。

版本 {#versions}

锁定目录从 7.4 记录该条件,并在正式快照及 19beta3 中出现;固定报告该码的路径 为 PostgreSQL 18.6 execSRF.c。

相关条件 {#related}

39P01, 39P03, 2F002

来源 {#sources}

可直接阅读固定的 execSRF.c 以及 materialize 路径(665-686 行);完整范围见结构化证据记录。

比较版本

SQLSTATE 证据与已记录的运行版本

claims · identity
{
  "claim_id": "identity",
  "limits": "",
  "method": "Read the fixed definition row.",
  "position": 0,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "39P02 is srf_protocol_violated in Class 39."
}
claims · return-modes
{
  "claim_id": "return-modes",
  "limits": "",
  "method": "Read the rsinfo.returnMode, isDone, and returnsSet checks.",
  "position": 1,
  "runtime": [],
  "sources": [
    "src.path.srf"
  ],
  "statement": "The executor reports this code when a set-returning function violates value-per-call or materialize mode, or supplies an unrecognized returnMode."
}
claims · boundary
{
  "claim_id": "boundary",
  "limits": "",
  "method": "Interpret the source checks in their executor context.",
  "position": 2,
  "runtime": [],
  "sources": [
    "src.path.srf"
  ],
  "statement": "The fixed path is an executor-to-set-returning-function contract, not an ordinary query row-count condition."
}
messages · message.srf-value-per-call
{
  "limits": "",
  "message_id": "message.srf-value-per-call",
  "path": "",
  "position": 0,
  "raw": {
    "id": "message.srf-value-per-call",
    "primary_template": "table-function protocol for value-per-call mode was not followed",
    "severity_source": "ERROR",
    "sources": [
      "src.path.srf"
    ],
    "sqlstate": "39P02"
  },
  "severity": "ERROR",
  "sources": [
    "src.path.srf"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "table-function protocol for value-per-call mode was not followed",
      "position": 0,
      "role": "",
      "template": "table-function protocol for value-per-call mode was not followed"
    }
  ]
}
messages · message.srf-materialize
{
  "limits": "",
  "message_id": "message.srf-materialize",
  "path": "",
  "position": 1,
  "raw": {
    "id": "message.srf-materialize",
    "primary_template": "table-function protocol for materialize mode was not followed",
    "severity_source": "ERROR",
    "sources": [
      "src.path.srf"
    ],
    "sqlstate": "39P02"
  },
  "severity": "ERROR",
  "sources": [
    "src.path.srf"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "table-function protocol for materialize mode was not followed",
      "position": 0,
      "role": "",
      "template": "table-function protocol for materialize mode was not followed"
    }
  ]
}
messages · message.srf-returnmode
{
  "limits": "",
  "message_id": "message.srf-returnmode",
  "path": "",
  "position": 2,
  "raw": {
    "id": "message.srf-returnmode",
    "primary_template": "unrecognized table-function returnMode: %d",
    "severity_source": "ERROR",
    "sources": [
      "src.path.srf"
    ],
    "sqlstate": "39P02"
  },
  "severity": "ERROR",
  "sources": [
    "src.path.srf"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "unrecognized table-function returnMode:",
      "position": 0,
      "role": "",
      "template": "unrecognized table-function returnMode: %d"
    }
  ]
}
sources · src.errcodes.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/errcodes.txt",
  "position": 0,
  "sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
  "source_id": "src.errcodes.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L312"
}
sources · src.calls.REL_18_6
{
  "commit": "",
  "docs_url": "",
  "kind": "local_artifact",
  "location": "",
  "path": "raw/calls/REL_18_6.jsonl",
  "position": 1,
  "sha256": "9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf",
  "source_id": "src.calls.REL_18_6",
  "tag": "",
  "url": ""
}
sources · src.path.srf
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/executor/execSRF.c",
  "position": 2,
  "sha256": "5c6038cbcc254113a39119af636331063b11d75ad7757b027620d78ed1ecdf2a",
  "source_id": "src.path.srf",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/executor/execSRF.c#L363-L365"
}

来源引用

完整定义与证据 JSON

定义来源

center · PostgreSQL 18 · english-manuals:8f8fa28d620ccffb8d980bb7920513dc200cbc354fffb8e01f1e4a96de151b41

正文语言: zh-Hans · english-manuals:8f8fa28d620ccffb8d980bb7920513dc200cbc354fffb8e01f1e4a96de151b41