{
  "schema": 1,
  "sqlstate": "21000",
  "condition_name": "cardinality_violation",
  "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"
    },
    {
      "id": "src.calls.REL_18_6",
      "kind": "local_artifact",
      "source_role": "source_call_scan",
      "sha256": "9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf"
    },
    {
      "id": "src.nodeSubplan.18.6",
      "kind": "upstream_source",
      "source_role": "source_path",
      "tag": "REL_18_6",
      "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
      "path": "src/backend/executor/nodeSubplan.c",
      "sha256": "c356a9812691f875974c1f476efa987015ba19e70a4be833a43b692f3554dc47",
      "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/executor/nodeSubplan.c#L296-L298"
    },
    {
      "id": "src.nodeModifyTable.18.6",
      "kind": "upstream_source",
      "source_role": "source_path",
      "tag": "REL_18_6",
      "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
      "path": "src/backend/executor/nodeModifyTable.c",
      "sha256": "0fc3cb180b3443f216142954e43d8ed5f84713d75094ce8cd2785ad8f604bd68",
      "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/executor/nodeModifyTable.c#L2804-L2809"
    },
    {
      "id": "doc.syntax.18.6",
      "kind": "upstream_source",
      "source_role": "official_documentation",
      "tag": "REL_18_6",
      "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
      "path": "doc/src/sgml/syntax.sgml",
      "sha256": "449b0c500fccca068d0f8a1db2a5ebb5430eb83e33f12c6cb310a01a7437b635",
      "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/doc/src/sgml/syntax.sgml#L2232-L2238",
      "docs_url": "https://www.postgresql.org/docs/18/functions-subquery.html"
    }
  ],
  "claims": [
    {
      "id": "identity",
      "statement": "21000 is the cardinality_violation condition in Class 21.",
      "sources": [
        "src.errcodes.18.6"
      ],
      "method": "Read the fixed errcodes.txt row and macro mapping.",
      "limits": "This identifies the protocol condition; it does not select one particular SQL operation."
    },
    {
      "id": "scalar-subquery",
      "statement": "A scalar subquery used as an expression must yield at most one row; the executor reports 21000 when it produces a second row.",
      "sources": [
        "src.nodeSubplan.18.6",
        "src.calls.REL_18_6",
        "doc.syntax.18.6"
      ],
      "method": "Trace ERRCODE_CARDINALITY_VIOLATION and the fixed scalar-subquery documentation.",
      "limits": "A scalar subquery returning zero rows yields NULL; the error is the more-than-one-row case."
    },
    {
      "id": "dml-conflict",
      "statement": "ON CONFLICT DO UPDATE and MERGE can use 21000 when one command would affect the same target row a second time.",
      "sources": [
        "src.nodeModifyTable.18.6",
        "src.calls.REL_18_6"
      ],
      "method": "Read the separate nodeModifyTable report groups and their hints.",
      "limits": "This is a command-level cardinality conflict, not a generic duplicate-key error."
    },
    {
      "id": "runtime",
      "statement": "The selected scalar-subquery case returned 21000 on PostgreSQL 18.6 and 10.21, remained usable in autocommit mode, and succeeded after a one-row predicate.",
      "sources": [
        "runtime.21000-batch1-latest-20260909.latest",
        "runtime.21000-batch1-pg10-20260909.pg10"
      ],
      "method": "Compare the selected summaries, raw outputs, and shared snippet registry.",
      "limits": "The run covers one scalar-subquery path; it does not validate ON CONFLICT, MERGE, PL/pgSQL, dblink, or materialized-view paths."
    }
  ],
  "messages": [
    {
      "id": "message.scalar-subquery",
      "sqlstate": "21000",
      "primary_template": "more than one row returned by a subquery used as an expression",
      "severity_source": "ERROR",
      "sources": [
        "src.nodeSubplan.18.6"
      ],
      "limits": "This is the scalar-subquery template; other 21000 paths have different templates."
    },
    {
      "id": "dml-second-target",
      "sqlstate": "21000",
      "primary_template": "%s command cannot affect row a second time",
      "severity_source": "ERROR",
      "sources": [
        "src.nodeModifyTable.18.6"
      ],
      "limits": "The %s substitution is ON CONFLICT DO UPDATE or MERGE; the hint branch is command-specific.",
      "hint_template": "Ensure that no rows proposed for insertion within the same command have duplicate constrained values. / Ensure that not more than one source row matches any one target row."
    }
  ],
  "usage_evidence": [
    {
      "scope": "scalar-subquery-runtime",
      "status": "observed_runtime",
      "evidence_ids": [
        "runtime",
        "runtime.21000-batch1-latest-20260909.latest",
        "runtime.21000-batch1-pg10-20260909.pg10"
      ]
    },
    {
      "scope": "condition-and-source-paths",
      "status": "source_path_confirmed",
      "evidence_ids": [
        "identity",
        "scalar-subquery",
        "dml-conflict"
      ]
    }
  ],
  "runtime": [
    {
      "id": "runtime.21000-batch1-latest-20260909.latest",
      "run_id": "21000-batch1-latest-20260909",
      "target": "latest",
      "server_version": "18.6 (Homebrew)",
      "server_version_num": 180006,
      "status": "passed",
      "cases": [
        "scalar_subquery_cardinality"
      ],
      "summary_sha256": "a0042f75764d6b803750aeacc2e4a1b94f5f9b61fd6a61dc30f77e72937fef9f",
      "raw_sha256": "d2b3cff4ba74cebed39719769cc781555a43805354c0ed9eaa1727b654617c86",
      "snippet_registry": {
        "sha256": "6d820e94518ffca97f407956fdc2df104d47b14263d3117ff59dbc4409774dc2"
      },
      "case_manifest": {
        "sha256": "26525997f7d1220ec953f6451c63ddbbe788272d43050d71be9cfce2f23f17ca"
      },
      "observed": {
        "sqlstate": "21000",
        "primary": "more than one row returned by a subquery used as an expression",
        "status_after_error": "IDLE",
        "valid_result": 1
      }
    },
    {
      "id": "runtime.21000-batch1-pg10-20260909.pg10",
      "run_id": "21000-batch1-pg10-20260909",
      "target": "pg10",
      "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
      "server_version_num": 100021,
      "status": "passed",
      "cases": [
        "scalar_subquery_cardinality"
      ],
      "summary_sha256": "87675457e4ff52f78f0c0075aab0be5e82e290554bafda5515cdbf8abf5f1979",
      "raw_sha256": "ec026f72b65e378fcfcb5b99ccc98055bc899aa3ad811a6cc52b4908c57e7c30",
      "snippet_registry": {
        "sha256": "6d820e94518ffca97f407956fdc2df104d47b14263d3117ff59dbc4409774dc2"
      },
      "case_manifest": {
        "sha256": "26525997f7d1220ec953f6451c63ddbbe788272d43050d71be9cfce2f23f17ca"
      },
      "observed": {
        "sqlstate": "21000",
        "primary": "more than one row returned by a subquery used as an expression",
        "status_after_error": "IDLE",
        "valid_result": 1
      }
    }
  ]
}
