{
  "schema": 1,
  "sqlstate": "23P01",
  "condition_name": "exclusion_violation",
  "runner": "scripts/verify_cases.py",
  "targets": {
    "latest": {
      "binary": "Homebrew PostgreSQL 18.6",
      "required": true
    },
    "pg10": {
      "image": "postgres:10",
      "required": true
    }
  },
  "cases": [
    {
      "id": "overlapping_range_exclusion",
      "versions": [
        "10",
        "18"
      ],
      "preconditions": [
        "A range column has a GiST exclusion constraint using &&",
        "The second range overlaps the committed first range"
      ],
      "trigger": "Insert an overlapping range.",
      "assertions": [
        "SQLSTATE is 23P01",
        "The exclusion constraint is identified",
        "A non-overlapping range can be inserted afterward"
      ],
      "repair": "Choose a non-overlapping interval or resolve the conflicting reservation according to business rules; do not treat exclusion as a generic duplicate-key check.",
      "cleanup": "Drop the case schema with an owner connection."
    }
  ],
  "evidence_status": "authored",
  "snippets": [
    {
      "id": "overlapping_range_exclusion",
      "case_id": "overlapping_range_exclusion",
      "language": "sql",
      "statements": {
        "create": "CREATE TABLE bookings(id integer PRIMARY KEY, during int4range NOT NULL, CONSTRAINT bookings_no_overlap EXCLUDE USING gist (during WITH &&))",
        "seed": "INSERT INTO bookings VALUES (1, int4range(1, 10))",
        "trigger": "INSERT INTO bookings VALUES (2, int4range(5, 12))",
        "repair": "INSERT INTO bookings VALUES (2, int4range(10, 12))",
        "verify": "SELECT id, during::text FROM bookings ORDER BY id"
      }
    }
  ],
  "runtime": [
    {
      "id": "runtime.23P01-batch1-latest-20260909.latest",
      "run_id": "23P01-batch1-latest-20260909",
      "target": "latest",
      "server_version": "18.6 (Homebrew)",
      "server_version_num": 180006,
      "status": "passed",
      "cases": [
        "overlapping_range_exclusion"
      ],
      "summary_sha256": "5e613eec8134801dfb3a603e7926418ee5d73b585546fd1aaa9004eeec553ef4",
      "raw_sha256": "b4e9ebe13743c12d84be1113ebdcec01c12ae79368e9b85b4ff1e01179dc7880",
      "snippet_registry": {
        "sha256": "475f58dda688a5864436d67e18f16abfbfae0b178acecaabe66ebaca7ab3c585"
      },
      "case_manifest": {
        "sha256": "6dcb833ed64435a75016520f520cbb1abffc7d8751eb9195dc8ad5ffa2a9680e"
      },
      "observed": {
        "sqlstate": "23P01",
        "primary": "conflicting key value violates exclusion constraint \"bookings_no_overlap\"",
        "detail": "Key (during)=([5,12)) conflicts with existing key (during)=([1,10)).",
        "constraint": "bookings_no_overlap",
        "status_after_error": "IDLE",
        "rows": [
          [
            1,
            "[1,10)"
          ],
          [
            2,
            "[10,12)"
          ]
        ]
      },
      "result": {
        "status": "passed",
        "environment": {
          "TimeZone": "Asia/Shanghai",
          "backend_pid": 33595,
          "binary": {
            "bindir": "/opt/homebrew/Cellar/postgresql@18/18.6/bin",
            "pg_config": "/opt/homebrew/bin/pg_config",
            "pg_config_version": "PostgreSQL 18.6 (Homebrew)",
            "postgres": "/opt/homebrew/Cellar/postgresql@18/18.6/bin/postgres"
          },
          "connection_scope": "runner-owned localhost port",
          "current_user": "runner",
          "docker": {},
          "lc_messages": "C",
          "libpq_version": "18.6",
          "locale": "en_US.UTF-8",
          "log_destination": "csvlog,jsonlog",
          "log_error_verbosity": "verbose",
          "log_min_error_statement": "error",
          "log_min_messages": "error",
          "logging_collector": "on",
          "machine": "arm64",
          "max_connections": "100",
          "platform": "macOS-26.6.2-arm64-arm-64bit-Mach-O",
          "psycopg_version": "3.3.5",
          "python_version": "3.14.6 (main, Jun 10 2026, 10:03:53) [Clang 21.0.0 (clang-2100.0.123.102)]",
          "server_encoding": "UTF8",
          "server_version": "18.6 (Homebrew)",
          "server_version_num": "180006",
          "target_kind": "latest",
          "wal_level": "logical"
        },
        "cases": [
          {
            "assertions": [
              {
                "expected": "23P01",
                "name": "exclusion sqlstate",
                "observed": "23P01",
                "passed": true
              },
              {
                "expected": "bookings_no_overlap",
                "name": "exclusion constraint is identified",
                "observed": "bookings_no_overlap",
                "passed": true
              },
              {
                "expected": "IDLE",
                "name": "autocommit remains idle",
                "observed": {
                  "after_error": "IDLE",
                  "after_valid": "IDLE"
                },
                "passed": true
              },
              {
                "expected": "two non-overlapping ranges",
                "name": "non-overlap repair committed",
                "observed": [
                  [
                    1,
                    "[1,10)"
                  ],
                  [
                    2,
                    "[10,12)"
                  ]
                ],
                "passed": true
              }
            ],
            "case_id": "overlapping_range_exclusion",
            "cleanup": {
              "errors": [],
              "passed": true
            },
            "elapsed_seconds": 0.015,
            "observed": {
              "connection_autocommit": true,
              "diagnostic": {
                "column_name": null,
                "constraint_name": "bookings_no_overlap",
                "context": null,
                "datatype_name": null,
                "exception_type": "ExclusionViolation",
                "internal_position": null,
                "internal_query": null,
                "message_detail": "Key (during)=([5,12)) conflicts with existing key (during)=([1,10)).",
                "message_hint": null,
                "message_primary": "conflicting key value violates exclusion constraint \"bookings_no_overlap\"",
                "schema_name": "c23p01_overlapping_range_exclusion",
                "severity": "ERROR",
                "severity_nonlocalized": "ERROR",
                "source_file": "execIndexing.c",
                "source_function": "check_exclusion_or_unique_constraint",
                "source_line": "937",
                "sqlstate": "23P01",
                "statement_position": null,
                "table_name": "bookings",
                "text": "conflicting key value violates exclusion constraint \"bookings_no_overlap\"\nDETAIL:  Key (during)=([5,12)) conflicts with existing key (during)=([1,10))."
              },
              "rows": [
                [
                  1,
                  "[1,10)"
                ],
                [
                  2,
                  "[10,12)"
                ]
              ],
              "statuses": {
                "after_error": "IDLE",
                "after_valid": "IDLE"
              }
            },
            "schema": "c23p01_overlapping_range_exclusion",
            "status": "passed"
          }
        ]
      }
    },
    {
      "id": "runtime.23P01-batch1-pg10-20260909.pg10",
      "run_id": "23P01-batch1-pg10-20260909",
      "target": "pg10",
      "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
      "server_version_num": 100021,
      "status": "passed",
      "cases": [
        "overlapping_range_exclusion"
      ],
      "summary_sha256": "2b071d07ad5977b4fd9133f9815a92fc3fca27980659f26654b8dc3793abd767",
      "raw_sha256": "1975e9348838d73f3433c2da02a3f3972dc3670e24bc89d73d631cd35b219165",
      "snippet_registry": {
        "sha256": "475f58dda688a5864436d67e18f16abfbfae0b178acecaabe66ebaca7ab3c585"
      },
      "case_manifest": {
        "sha256": "6dcb833ed64435a75016520f520cbb1abffc7d8751eb9195dc8ad5ffa2a9680e"
      },
      "observed": {
        "sqlstate": "23P01",
        "primary": "conflicting key value violates exclusion constraint \"bookings_no_overlap\"",
        "detail": "Key (during)=([5,12)) conflicts with existing key (during)=([1,10)).",
        "constraint": "bookings_no_overlap",
        "status_after_error": "IDLE",
        "rows": [
          [
            1,
            "[1,10)"
          ],
          [
            2,
            "[10,12)"
          ]
        ]
      },
      "result": {
        "status": "passed",
        "environment": {
          "TimeZone": "Etc/UTC",
          "backend_pid": 79,
          "binary": {},
          "connection_scope": "runner-owned localhost port",
          "current_user": "postgres",
          "docker": {
            "architecture": "arm64",
            "command": "/usr/local/bin/docker",
            "id": "sha256:b2baf8998630663d21370da06387c950e587071bdd307ee34e661cdcc7442bcc",
            "image": "postgres:10",
            "image_created": "2022-06-23T09:11:18.374607054Z",
            "os": "linux",
            "repo_digests": [
              "postgres@sha256:b2baf8998630663d21370da06387c950e587071bdd307ee34e661cdcc7442bcc"
            ]
          },
          "lc_messages": "en_US.utf8",
          "libpq_version": "18.6",
          "locale": "en_US.UTF-8",
          "log_destination": "csvlog",
          "log_error_verbosity": "verbose",
          "log_min_error_statement": "error",
          "log_min_messages": "error",
          "logging_collector": "on",
          "machine": "arm64",
          "max_connections": "100",
          "platform": "macOS-26.6.2-arm64-arm-64bit-Mach-O",
          "psycopg_version": "3.3.5",
          "python_version": "3.14.6 (main, Jun 10 2026, 10:03:53) [Clang 21.0.0 (clang-2100.0.123.102)]",
          "server_encoding": "UTF8",
          "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
          "server_version_num": "100021",
          "target_kind": "pg10",
          "wal_level": "logical"
        },
        "cases": [
          {
            "assertions": [
              {
                "expected": "23P01",
                "name": "exclusion sqlstate",
                "observed": "23P01",
                "passed": true
              },
              {
                "expected": "bookings_no_overlap",
                "name": "exclusion constraint is identified",
                "observed": "bookings_no_overlap",
                "passed": true
              },
              {
                "expected": "IDLE",
                "name": "autocommit remains idle",
                "observed": {
                  "after_error": "IDLE",
                  "after_valid": "IDLE"
                },
                "passed": true
              },
              {
                "expected": "two non-overlapping ranges",
                "name": "non-overlap repair committed",
                "observed": [
                  [
                    1,
                    "[1,10)"
                  ],
                  [
                    2,
                    "[10,12)"
                  ]
                ],
                "passed": true
              }
            ],
            "case_id": "overlapping_range_exclusion",
            "cleanup": {
              "errors": [],
              "passed": true
            },
            "elapsed_seconds": 0.019,
            "observed": {
              "connection_autocommit": true,
              "diagnostic": {
                "column_name": null,
                "constraint_name": "bookings_no_overlap",
                "context": null,
                "datatype_name": null,
                "exception_type": "ExclusionViolation",
                "internal_position": null,
                "internal_query": null,
                "message_detail": "Key (during)=([5,12)) conflicts with existing key (during)=([1,10)).",
                "message_hint": null,
                "message_primary": "conflicting key value violates exclusion constraint \"bookings_no_overlap\"",
                "schema_name": "c23p01_overlapping_range_exclusion",
                "severity": "ERROR",
                "severity_nonlocalized": "ERROR",
                "source_file": "execIndexing.c",
                "source_function": "check_exclusion_or_unique_constraint",
                "source_line": "836",
                "sqlstate": "23P01",
                "statement_position": null,
                "table_name": "bookings",
                "text": "conflicting key value violates exclusion constraint \"bookings_no_overlap\"\nDETAIL:  Key (during)=([5,12)) conflicts with existing key (during)=([1,10))."
              },
              "rows": [
                [
                  1,
                  "[1,10)"
                ],
                [
                  2,
                  "[10,12)"
                ]
              ],
              "statuses": {
                "after_error": "IDLE",
                "after_valid": "IDLE"
              }
            },
            "schema": "c23p01_overlapping_range_exclusion",
            "status": "passed"
          }
        ]
      }
    }
  ]
}
