{
  "schema": 1,
  "sqlstate": "23503",
  "condition_name": "foreign_key_violation",
  "sources": [
    {
      "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
      "id": "src.errcodes.18.6",
      "location": "lines 235-241",
      "path": "src/backend/utils/errcodes.txt",
      "sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
      "tag": "REL_18_6",
      "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt"
    },
    {
      "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
      "id": "src.ri-triggers.18.6",
      "location": "lines 2761-2809",
      "path": "src/backend/utils/adt/ri_triggers.c",
      "sha256": "a3fed49fbda88fe0fe5bcf35eb019fced28596ae4046233f2acb2eb9f90ab1da",
      "tag": "REL_18_6",
      "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/ri_triggers.c#L2761-L2809"
    },
    {
      "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
      "id": "doc.ddl.18.6",
      "location": "foreign-key constraints",
      "path": "doc/src/sgml/ddl.sgml",
      "sha256": "ce1919d9236f2e71672660e1a347146472e966e4d19b77fde5ae345dd1db6ec7",
      "tag": "REL_18_6",
      "url": "https://www.postgresql.org/docs/18/ddl-constraints.html#DDL-CONSTRAINTS-FK"
    },
    {
      "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
      "id": "doc.protocol.18",
      "location": "ErrorResponse fields",
      "path": "doc/src/sgml/protocol.sgml",
      "sha256": "745339e07ebbc2bb67d98b258e25772ada644ef26011e3cd6b3fcbb435235f89",
      "tag": "REL_18_6",
      "url": "https://www.postgresql.org/docs/18/protocol-error-fields.html"
    }
  ],
  "claims": [
    {
      "id": "identity.class-and-condition",
      "limits": "This establishes directory identity; it does not enumerate every foreign-key trigger path.",
      "method": "Read the frozen errcodes.txt class and condition rows.",
      "sources": [
        "src.errcodes.18.6"
      ],
      "statement": "23503 is the foreign_key_violation condition in Class 23 integrity_constraint_violation."
    },
    {
      "id": "runtime.ri-report",
      "limits": "DETAIL is conditional on diagnostic visibility and the operation; parent deletion and deferred checks use different message shapes or timing.",
      "method": "Trace ri_ReportViolation in the fixed source and compare the protocol diagnostics from fk_insert_missing_parent.",
      "sources": [
        "src.ri-triggers.18.6",
        "doc.protocol.18"
      ],
      "statement": "The ordinary missing-parent path reports insert or update on table \"%s\" violates foreign key constraint \"%s\", conditionally adds Key (%s)=(%s) is not present in table \"%s\"., and attaches the child table and constraint."
    },
    {
      "id": "mechanism.parent-actions",
      "limits": "This is a source boundary for parent-key operations, not runtime evidence for the missing-parent child insert case. SQLSTATE and primary text depend on the action branch and release.",
      "method": "Trace the fixed ri_ReportViolation branches for ordinary parent references and is_restrict, then compare the foreign-key action documentation.",
      "sources": [
        "src.ri-triggers.18.6",
        "doc.ddl.18.6"
      ],
      "statement": "NO ACTION parent checks use the ordinary foreign-key violation branch and can be deferred when the constraint is deferrable; the fixed PostgreSQL 18.6 RESTRICT branch uses ERRCODE_RESTRICT_VIOLATION (23001) with a RESTRICT-specific message and cannot be deferred."
    },
    {
      "id": "runtime.transaction-recovery",
      "limits": "The representative case uses an immediate foreign key and does not establish deferred timing, cascading actions, or concurrent parent creation.",
      "method": "Run the missing-parent case on isolated PostgreSQL 18.6 and 10.21 targets and assert status transitions and the post-commit row.",
      "sources": [
        "doc.ddl.18.6"
      ],
      "statement": "A failed child write leaves an explicit transaction INERROR until rollback; a valid parent and child can then be committed."
    }
  ],
  "messages": [
    {
      "detail_template": "Key (%s)=(%s) is not present in table \"%s\".",
      "id": "message.ri.insert-update",
      "limits": "The detail is conditional; parent delete/update paths use different primary and detail templates.",
      "primary_template": "insert or update on table \"%s\" violates foreign key constraint \"%s\"",
      "severity_source": "E",
      "sources": [
        "src.ri-triggers.18.6"
      ],
      "sqlstate": "23503"
    },
    {
      "id": "message.ri.parent",
      "limits": "This is the ordinary parent-key update/delete branch; the fixed RESTRICT branch uses SQLSTATE 23001 and different wording.",
      "primary_template": "update or delete on table \"%s\" violates foreign key constraint \"%s\" on table \"%s\"",
      "detail_template": "Key (%s)=(%s) is still referenced from table \"%s\".",
      "severity_source": "explicit ERROR with ERRCODE_FOREIGN_KEY_VIOLATION",
      "sources": [
        "src.ri-triggers.18.6"
      ],
      "sqlstate": "23503"
    }
  ],
  "usage_evidence": [
    {
      "evidence_ids": [
        "runtime.23503-final-20260909.latest",
        "runtime.23503-final-20260909.pg10",
        "runtime.23503-explicit-begin-final-20260909.latest",
        "runtime.23503-explicit-begin-final-20260909.pg10",
        "runtime.23503-registry-final-20260909.latest",
        "runtime.23503-registry-final-20260909.pg10",
        "runtime.23503-fk-manual-final-20260909.latest",
        "runtime.23503-fk-manual-final-20260909.pg10"
      ],
      "notes": "The selected manual-boundary rerun keeps the page's visible repair transaction boundary identical to the registry sequence and records autocommit=True on both targets.",
      "scope": "Missing-parent insert, transaction recovery, diagnostics, and post-commit repair",
      "status": "observed_runtime"
    },
    {
      "evidence_ids": [
        "identity.class-and-condition",
        "src.errcodes.18.6"
      ],
      "scope": "Foreign-key condition identity in the source directory",
      "status": "definition_only"
    },
    {
      "evidence_ids": [
        "runtime.ri-report",
        "mechanism.parent-actions",
        "message.ri.insert-update",
        "message.ri.parent",
        "src.ri-triggers.18.6",
        "doc.ddl.18.6",
        "doc.protocol.18"
      ],
      "scope": "Foreign-key child and parent action message branches",
      "status": "source_path_confirmed"
    }
  ],
  "runtime": [
    {
      "cases": [
        "fk_insert_missing_parent"
      ],
      "id": "runtime.23503-final-20260909.latest",
      "run_id": "23503-final-20260909",
      "server_version": "18.6 (Homebrew)",
      "server_version_num": 180006,
      "status": "passed",
      "target": "latest"
    },
    {
      "cases": [
        "fk_insert_missing_parent"
      ],
      "id": "runtime.23503-final-20260909.pg10",
      "image": "postgres@sha256:b2baf8998630663d21370da06387c950e587071bdd307ee34e661cdcc7442bcc",
      "run_id": "23503-final-20260909",
      "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
      "server_version_num": 100021,
      "status": "passed",
      "target": "pg10"
    },
    {
      "cases": [
        "fk_insert_missing_parent"
      ],
      "id": "runtime.23503-explicit-begin-final-20260909.latest",
      "limits": "This rerun proves the page's explicit BEGIN around the post-rollback repair; it does not test deferred or cascading foreign keys.",
      "observed": {
        "repair_transaction": "BEGIN; INSERT parent; INSERT child; COMMIT",
        "rows": [
          [
            1,
            99
          ]
        ],
        "sqlstate": "23503",
        "status_after_error": "INERROR",
        "status_after_rollback": "IDLE"
      },
      "raw_sha256": "448d0fb4e045829071281cbf3b41be2be070932288191012cc3b766a038f0f2d",
      "run_id": "23503-explicit-begin-final-20260909",
      "server_version": "18.6 (Homebrew)",
      "server_version_num": 180006,
      "status": "passed",
      "summary_sha256": "dcbbb3ede7e424622275a30b8e4ddee2e8e0dc71ea46a78aba1f9c40403626a0",
      "target": "latest"
    },
    {
      "cases": [
        "fk_insert_missing_parent"
      ],
      "id": "runtime.23503-explicit-begin-final-20260909.pg10",
      "image": "postgres@sha256:b2baf8998630663d21370da06387c950e587071bdd307ee34e661cdcc7442bcc",
      "limits": "This rerun proves the page's explicit BEGIN around the post-rollback repair; it does not test deferred or cascading foreign keys.",
      "observed": {
        "repair_transaction": "BEGIN; INSERT parent; INSERT child; COMMIT",
        "rows": [
          [
            1,
            99
          ]
        ],
        "sqlstate": "23503",
        "status_after_error": "INERROR",
        "status_after_rollback": "IDLE"
      },
      "raw_sha256": "0d3f8a56d5b50bb184ce791c5c88db1e1ddac4f43ba220829a773796c044f58e",
      "run_id": "23503-explicit-begin-final-20260909",
      "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
      "server_version_num": 100021,
      "status": "passed",
      "summary_sha256": "c92079153f22913d9a75ccf5dbbe19d4983c75f553572cdc10e755d3fc8b943e",
      "target": "pg10"
    },
    {
      "cases": [
        "fk_insert_missing_parent"
      ],
      "id": "runtime.23503-registry-final-20260909.latest",
      "observed": {
        "message_detail": "Key (parent_id)=(99) is not present in table \"parents\".",
        "message_primary": "insert or update on table \"children\" violates foreign key constraint \"children_parent_fk\"",
        "rows": [
          [
            1,
            99
          ]
        ],
        "source": "ri_triggers.c / ri_ReportViolation / line 2783",
        "sqlstate": "23503",
        "statuses": {
          "after_commit": "IDLE",
          "after_error": "INERROR",
          "after_rollback": "IDLE"
        }
      },
      "raw_sha256": "977b16fea3508fc6efef5a9d353500ae0036dfa28bab4e857eba86167a5b52af",
      "run_id": "23503-registry-final-20260909",
      "server_version": "18.6 (Homebrew)",
      "server_version_num": 180006,
      "snippet_registry": {
        "sha256": "63d0f78a47023e343cf8b38f4168021e68ccdd875bb64f35b5e42e68394779e3"
      },
      "status": "passed",
      "summary_sha256": "301bd9183ceb223bd5898315316ab5c666a89dc10c5b48333e54bcdafcab873a",
      "target": "latest"
    },
    {
      "cases": [
        "fk_insert_missing_parent"
      ],
      "id": "runtime.23503-registry-final-20260909.pg10",
      "image": "postgres@sha256:b2baf8998630663d21370da06387c950e587071bdd307ee34e661cdcc7442bcc",
      "observed": {
        "message_detail": "Key (parent_id)=(99) is not present in table \"parents\".",
        "message_primary": "insert or update on table \"children\" violates foreign key constraint \"children_parent_fk\"",
        "rows": [
          [
            1,
            99
          ]
        ],
        "source": "ri_triggers.c / ri_ReportViolation / line 3266",
        "sqlstate": "23503",
        "statuses": {
          "after_commit": "IDLE",
          "after_error": "INERROR",
          "after_rollback": "IDLE"
        }
      },
      "raw_sha256": "02bc2125919383ed4e9847d7cdf45e3ca235b325c5c36fa9d9e1984d27a45c5d",
      "run_id": "23503-registry-final-20260909",
      "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
      "server_version_num": 100021,
      "snippet_registry": {
        "sha256": "63d0f78a47023e343cf8b38f4168021e68ccdd875bb64f35b5e42e68394779e3"
      },
      "status": "passed",
      "summary_sha256": "0aba93166977cc979499f62acee75df0f0b86587e3b0309795da0de2476209de",
      "target": "pg10"
    },
    {
      "cases": [
        "fk_insert_missing_parent"
      ],
      "id": "runtime.23503-fk-manual-final-20260909.latest",
      "limits": "This run proves that the registry BEGIN/ROLLBACK/BEGIN/COMMIT sequence executes with autocommit=True; it covers the single-parent foreign-key case.",
      "observed": {
        "connection_autocommit": true,
        "diagnostic": {
          "message_detail": "Key (parent_id)=(99) is not present in table \"parents\".",
          "message_primary": "insert or update on table \"children\" violates foreign key constraint \"children_parent_fk\"",
          "sqlstate": "23503"
        },
        "rows": [
          [
            1,
            99
          ]
        ],
        "statuses": {
          "after_commit": "IDLE",
          "after_error": "INERROR",
          "after_rollback": "IDLE"
        },
        "transaction_control": [
          "BEGIN",
          "ROLLBACK",
          "BEGIN",
          "COMMIT"
        ]
      },
      "raw_sha256": "442dbfa57497ce15440689645d531f493890d35e8841308ade267514244b68e5",
      "run_id": "23503-fk-manual-final-20260909",
      "server_version": "18.6 (Homebrew)",
      "server_version_num": 180006,
      "snippet_registry": {
        "sha256": "63d0f78a47023e343cf8b38f4168021e68ccdd875bb64f35b5e42e68394779e3"
      },
      "status": "passed",
      "summary_sha256": "e3029aab946d6e097e1c741d918937583f4ae6c8f0af24e118667b50396bcddb",
      "target": "latest"
    },
    {
      "cases": [
        "fk_insert_missing_parent"
      ],
      "id": "runtime.23503-fk-manual-final-20260909.pg10",
      "image": "postgres@sha256:b2baf8998630663d21370da06387c950e587071bdd307ee34e661cdcc7442bcc",
      "limits": "This run proves that the registry BEGIN/ROLLBACK/BEGIN/COMMIT sequence executes with autocommit=True; it covers the single-parent foreign-key case.",
      "observed": {
        "connection_autocommit": true,
        "diagnostic": {
          "message_detail": "Key (parent_id)=(99) is not present in table \"parents\".",
          "message_primary": "insert or update on table \"children\" violates foreign key constraint \"children_parent_fk\"",
          "sqlstate": "23503"
        },
        "rows": [
          [
            1,
            99
          ]
        ],
        "statuses": {
          "after_commit": "IDLE",
          "after_error": "INERROR",
          "after_rollback": "IDLE"
        },
        "transaction_control": [
          "BEGIN",
          "ROLLBACK",
          "BEGIN",
          "COMMIT"
        ]
      },
      "raw_sha256": "05887d0f8e900ab9230ac677b112119303e6de9d2bde0da7f743e1649bd213be",
      "run_id": "23503-fk-manual-final-20260909",
      "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
      "server_version_num": 100021,
      "snippet_registry": {
        "sha256": "63d0f78a47023e343cf8b38f4168021e68ccdd875bb64f35b5e42e68394779e3"
      },
      "status": "passed",
      "summary_sha256": "433729dd2e043777d52910ceb7ca71c437a06d0a746b42385f5a7c5411893e68",
      "target": "pg10"
    }
  ]
}
