{
  "schema": 1,
  "sqlstate": "22P04",
  "condition_name": "bad_copy_file_format",
  "sources": [
    {
      "id": "src.errcodes.18.6",
      "kind": "upstream_source",
      "source_role": "condition_definition",
      "tag": "REL_18_6",
      "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
      "path": "src/backend/utils/errcodes.txt",
      "sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
      "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L208",
      "lines": "208"
    },
    {
      "id": "src.path.binary-header",
      "kind": "upstream_source",
      "source_role": "resolved_report_context",
      "tag": "REL_18_6",
      "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
      "path": "src/backend/commands/copyfromparse.c",
      "sha256": "bc42754023579cd782a3cb3f144ad2c2c3d3aa46119eb7567fcdb05f2d445571",
      "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/copyfromparse.c#L190",
      "lines": "190-228"
    },
    {
      "id": "src.path.text-header",
      "kind": "upstream_source",
      "source_role": "resolved_report_context",
      "tag": "REL_18_6",
      "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
      "path": "src/backend/commands/copyfromparse.c",
      "sha256": "bc42754023579cd782a3cb3f144ad2c2c3d3aa46119eb7567fcdb05f2d445571",
      "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/copyfromparse.c#L779",
      "lines": "779-827"
    },
    {
      "id": "src.path.text-row",
      "kind": "upstream_source",
      "source_role": "resolved_report_context",
      "tag": "REL_18_6",
      "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
      "path": "src/backend/commands/copyfromparse.c",
      "sha256": "bc42754023579cd782a3cb3f144ad2c2c3d3aa46119eb7567fcdb05f2d445571",
      "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/copyfromparse.c#L937",
      "lines": "937-977"
    },
    {
      "id": "src.path.on-error",
      "kind": "upstream_source",
      "source_role": "resolved_report_context",
      "tag": "REL_18_6",
      "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
      "path": "src/backend/commands/copyfromparse.c",
      "sha256": "bc42754023579cd782a3cb3f144ad2c2c3d3aa46119eb7567fcdb05f2d445571",
      "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/copyfromparse.c#L1026",
      "lines": "1026-1073"
    },
    {
      "id": "src.path.binary-row",
      "kind": "upstream_source",
      "source_role": "resolved_report_context",
      "tag": "REL_18_6",
      "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
      "path": "src/backend/commands/copyfromparse.c",
      "sha256": "bc42754023579cd782a3cb3f144ad2c2c3d3aa46119eb7567fcdb05f2d445571",
      "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/copyfromparse.c#L1084",
      "lines": "1084-1130"
    },
    {
      "id": "src.path.line-framing",
      "kind": "upstream_source",
      "source_role": "resolved_report_context",
      "tag": "REL_18_6",
      "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
      "path": "src/backend/commands/copyfromparse.c",
      "sha256": "bc42754023579cd782a3cb3f144ad2c2c3d3aa46119eb7567fcdb05f2d445571",
      "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/copyfromparse.c#L1388",
      "lines": "1388-1432"
    },
    {
      "id": "src.path.copy-marker",
      "kind": "upstream_source",
      "source_role": "resolved_report_context",
      "tag": "REL_18_6",
      "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
      "path": "src/backend/commands/copyfromparse.c",
      "sha256": "bc42754023579cd782a3cb3f144ad2c2c3d3aa46119eb7567fcdb05f2d445571",
      "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/copyfromparse.c#L1465",
      "lines": "1465-1500"
    },
    {
      "id": "src.path.csv",
      "kind": "upstream_source",
      "source_role": "resolved_report_context",
      "tag": "REL_18_6",
      "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
      "path": "src/backend/commands/copyfromparse.c",
      "sha256": "bc42754023579cd782a3cb3f144ad2c2c3d3aa46119eb7567fcdb05f2d445571",
      "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/copyfromparse.c#L1818",
      "lines": "1818-1922"
    },
    {
      "id": "src.path.binary-field",
      "kind": "upstream_source",
      "source_role": "resolved_report_context",
      "tag": "REL_18_6",
      "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
      "path": "src/backend/commands/copyfromparse.c",
      "sha256": "bc42754023579cd782a3cb3f144ad2c2c3d3aa46119eb7567fcdb05f2d445571",
      "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/copyfromparse.c#L2012",
      "lines": "2012-2042"
    },
    {
      "id": "src.path.protocol-flags",
      "kind": "upstream_source",
      "source_role": "protocol_flow",
      "tag": "REL_18_6",
      "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
      "path": "src/backend/tcop/postgres.c",
      "sha256": "9fb62275b1badf94d01ab351337b60410cd9b3ab1fe63fa9f23d6d2185a21061",
      "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/tcop/postgres.c#L416-L445",
      "lines": "416-445"
    },
    {
      "id": "doc.protocol.copy",
      "kind": "upstream_source",
      "source_role": "official_documentation",
      "tag": "REL_18_6",
      "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
      "path": "doc/src/sgml/protocol.sgml",
      "sha256": "745339e07ebbc2bb67d98b258e25772ada644ef26011e3cd6b3fcbb435235f89",
      "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/doc/src/sgml/protocol.sgml#L1287-L1318",
      "lines": "1287-1318",
      "docs_url": "https://www.postgresql.org/docs/18/protocol.html"
    }
  ],
  "claims": [
    {
      "id": "identity",
      "statement": "22P04 is bad_copy_file_format in SQLSTATE Class 22.",
      "sources": [
        "src.errcodes.18.6"
      ],
      "method": "Read fixed definition."
    },
    {
      "id": "headers-and-fields",
      "statement": "The fixed COPY parser uses 22P04 for binary signature/flags/extension length, text or CSV header field counts and names, extra or missing fields, and binary row/field framing.",
      "sources": [
        "src.path.binary-header",
        "src.path.text-header",
        "src.path.text-row",
        "src.path.binary-row",
        "src.path.binary-field"
      ],
      "method": "Read the complete header, row, and field guards."
    },
    {
      "id": "csv-and-line-framing",
      "statement": "Text and CSV line framing errors, end-of-copy marker placement, and unterminated quoted fields use 22P04; CSV quoting and text escape rules choose different primary/hint variants.",
      "sources": [
        "src.path.line-framing",
        "src.path.copy-marker",
        "src.path.csv"
      ],
      "method": "Read the complete line and CSV parsers."
    },
    {
      "id": "on-error-boundary",
      "statement": "ON_ERROR IGNORE is applied around safe text/CSV type-input conversion failures and emits a skip notice; it does not turn COPY header, row framing, CSV quoting, or binary field structure errors into skippable rows.",
      "sources": [
        "src.path.on-error",
        "src.path.csv",
        "src.path.binary-row"
      ],
      "method": "Read InputFunctionCallSafe handling separately from structural parser errors.",
      "limits": "This is source-backed; no ON_ERROR runtime was executed."
    },
    {
      "id": "history",
      "statement": "The locked catalogue records 22P04 from 7.4; that boundary does not prove exact implementation introduction.",
      "sources": [
        "src.errcodes.18.6"
      ],
      "method": "Use catalogue boundary."
    },
    {
      "id": "copy-protocol",
      "statement": "Frontend COPY-in errors follow the protocol that started COPY: extended-query COPY discards frontend messages until Sync and then sends ReadyForQuery, while simple Query COPY discards the rest of the query and sends ReadyForQuery without Sync. The frontend loop marks extended messages for skip-until-Sync recovery, and ReadyForQuery reports status rather than replacing transaction recovery.",
      "sources": [
        "src.path.protocol-flags",
        "doc.protocol.copy"
      ],
      "method": "Read the frontend message flags and the fixed COPY-in protocol documentation."
    }
  ],
  "messages": [
    {
      "id": "message.signature",
      "sqlstate": "22P04",
      "primary_template": "COPY file signature not recognized",
      "severity_source": "ERROR",
      "sources": [
        "src.path.binary-header"
      ]
    },
    {
      "id": "message.header-flags",
      "sqlstate": "22P04",
      "primary_template": "invalid COPY file header (missing flags)",
      "severity_source": "ERROR",
      "sources": [
        "src.path.binary-header"
      ]
    },
    {
      "id": "message.header-critical",
      "sqlstate": "22P04",
      "primary_template": "unrecognized critical flags in COPY file header",
      "severity_source": "ERROR",
      "sources": [
        "src.path.binary-header"
      ]
    },
    {
      "id": "message.header-length",
      "sqlstate": "22P04",
      "primary_template": "invalid COPY file header (missing length)",
      "severity_source": "ERROR",
      "sources": [
        "src.path.binary-header"
      ]
    },
    {
      "id": "message.header-wrong-length",
      "sqlstate": "22P04",
      "primary_template": "invalid COPY file header (wrong length)",
      "severity_source": "ERROR",
      "sources": [
        "src.path.binary-header"
      ]
    },
    {
      "id": "message.header-fields",
      "sqlstate": "22P04",
      "primary_template": "wrong number of fields in header line: got %d, expected %d",
      "severity_source": "ERROR",
      "sources": [
        "src.path.text-header"
      ]
    },
    {
      "id": "message.header-name",
      "sqlstate": "22P04",
      "primary_template": "column name mismatch in header line field %d: got \"%s\", expected \"%s\"",
      "severity_source": "ERROR",
      "sources": [
        "src.path.text-header"
      ]
    },
    {
      "id": "message.extra",
      "sqlstate": "22P04",
      "primary_template": "extra data after last expected column",
      "severity_source": "ERROR",
      "sources": [
        "src.path.text-row"
      ]
    },
    {
      "id": "message.missing",
      "sqlstate": "22P04",
      "primary_template": "missing data for column \"%s\"",
      "severity_source": "ERROR",
      "sources": [
        "src.path.text-row"
      ]
    },
    {
      "id": "message.row-count",
      "sqlstate": "22P04",
      "primary_template": "row field count is %d, expected %d",
      "severity_source": "ERROR",
      "sources": [
        "src.path.binary-row"
      ]
    },
    {
      "id": "message.field-size",
      "sqlstate": "22P04",
      "primary_template": "invalid field size",
      "severity_source": "ERROR",
      "sources": [
        "src.path.binary-field"
      ]
    },
    {
      "id": "message.eof",
      "sqlstate": "22P04",
      "primary_template": "unexpected EOF in COPY data",
      "severity_source": "ERROR",
      "sources": [
        "src.path.binary-field"
      ]
    },
    {
      "id": "message.csv-unterminated",
      "sqlstate": "22P04",
      "primary_template": "unterminated CSV quoted field",
      "severity_source": "ERROR",
      "sources": [
        "src.path.csv"
      ]
    },
    {
      "id": "message.literal-cr",
      "sqlstate": "22P04",
      "primary_template": "literal carriage return found in data",
      "severity_source": "ERROR",
      "sources": [
        "src.path.line-framing"
      ],
      "hint_template": "Use \"\\r\" to represent carriage return."
    },
    {
      "id": "message.csv-cr",
      "sqlstate": "22P04",
      "primary_template": "unquoted carriage return found in data",
      "severity_source": "ERROR",
      "sources": [
        "src.path.line-framing"
      ],
      "hint_template": "Use quoted CSV field to represent carriage return."
    },
    {
      "id": "message.literal-newline",
      "sqlstate": "22P04",
      "primary_template": "literal newline found in data",
      "severity_source": "ERROR",
      "sources": [
        "src.path.line-framing"
      ],
      "hint_template": "Use \"\\n\" to represent newline."
    },
    {
      "id": "message.csv-newline",
      "sqlstate": "22P04",
      "primary_template": "unquoted newline found in data",
      "severity_source": "ERROR",
      "sources": [
        "src.path.line-framing"
      ],
      "hint_template": "Use quoted CSV field to represent newline."
    },
    {
      "id": "message.marker-alone",
      "sqlstate": "22P04",
      "primary_template": "end-of-copy marker is not alone on its line",
      "severity_source": "ERROR",
      "sources": [
        "src.path.copy-marker"
      ]
    }
  ],
  "usage_evidence": [
    {
      "scope": "definition",
      "status": "definition_only",
      "evidence_ids": [
        "identity"
      ]
    },
    {
      "scope": "fixed-source-path",
      "status": "source_path_confirmed",
      "evidence_ids": [
        "headers-and-fields",
        "csv-and-line-framing",
        "on-error-boundary",
        "copy-protocol"
      ]
    },
    {
      "scope": "history",
      "status": "unknown",
      "evidence_ids": [
        "history"
      ]
    },
    {
      "scope": "natural-runtime",
      "status": "unknown",
      "evidence_ids": [
        "headers-and-fields",
        "csv-and-line-framing",
        "on-error-boundary",
        "copy-protocol"
      ]
    }
  ],
  "runtime": []
}
