{
  "schema": 1,
  "sqlstate": "34000",
  "condition_name": "invalid_cursor_name",
  "runner": "scripts/verify_cases.py",
  "targets": {
    "latest": {
      "binary": "Homebrew PostgreSQL 18.6",
      "required": true
    },
    "pg10": {
      "image": "postgres:10",
      "required": true
    }
  },
  "cases": [
    {
      "id": "cursor_lifecycle_recovery",
      "versions": [
        "10",
        "18"
      ],
      "preconditions": [
        "A runner-owned disposable target is provisioned."
      ],
      "trigger": "Declare and close a named cursor, attempt to use it again, then recreate it in a new explicit transaction on the same session.",
      "assertions": [
        "SQLSTATE is 34000",
        "The missing cursor diagnostic is preserved",
        "The failed block recovers through ROLLBACK",
        "A recreated cursor can FETCH and COMMIT"
      ],
      "repair": "Keep cursor use on the declaring backend session and respect its transaction lifetime; after an error, roll back before recreating it.",
      "cleanup": "Drop the case schema with an owner connection."
    }
  ],
  "evidence_status": "authored",
  "snippets": [
    {
      "id": "cursor_lifecycle_recovery",
      "case_id": "cursor_lifecycle_recovery",
      "language": "sql",
      "statements": {
        "begin": "BEGIN",
        "declare": "DECLARE cursor_name CURSOR FOR SELECT 1",
        "close": "CLOSE cursor_name",
        "missing": "FETCH cursor_name",
        "rollback": "ROLLBACK",
        "repair_begin": "BEGIN",
        "repair_declare": "DECLARE cursor_name CURSOR FOR SELECT 1",
        "fetch": "FETCH cursor_name",
        "repair_close": "CLOSE cursor_name",
        "commit": "COMMIT"
      }
    }
  ],
  "runtime": [
    {
      "id": "runtime.34000-batch34-20260909.latest",
      "run_id": "34000-batch34-20260909",
      "target": "latest",
      "server_version": "18.6 (Homebrew)",
      "status": "passed",
      "cases": [
        "cursor_lifecycle_recovery"
      ],
      "summary_sha256": "113822682213d49699a80ba97c2d3bad78a795790edfd32e7dbc362d16456e3e",
      "raw_sha256": "91c68dc423bfd301219891f250d584678c5300e1376c9fb6d75731b169d5f560",
      "case_manifest": {
        "sha256": "72347c5c8f1ccfaa18aced582e9ff5bf0f968eff0547c9a8f6521ed7fa3adb47"
      },
      "observed": {
        "sqlstate": "34000",
        "primary": "cursor \"case_cursor_aa951a82\" does not exist",
        "severity": "ERROR",
        "statuses": {
          "after_error": "INERROR",
          "after_repair": "IDLE",
          "after_rollback": "IDLE"
        },
        "repair": {
          "fetched_row": [
            1
          ]
        },
        "connection_autocommit": true
      },
      "snippet_registry": {
        "sha256": "ad5b519e8ca30fd2636b1d0bace32dc18558cccc7b9d360081c27b12a1405f08"
      },
      "result": {
        "status": "passed",
        "environment": {
          "TimeZone": "Asia/Shanghai",
          "backend_pid": 81308,
          "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": "34000",
                "name": "cursor sqlstate",
                "observed": "34000",
                "passed": true
              },
              {
                "expected": "cursor does not exist",
                "name": "missing cursor diagnostic",
                "observed": "cursor \"case_cursor_aa951a82\" does not exist",
                "passed": true
              },
              {
                "expected": "INERROR then IDLE",
                "name": "cursor error requires transaction recovery",
                "observed": {
                  "after_error": "INERROR",
                  "after_rollback": "IDLE"
                },
                "passed": true
              },
              {
                "expected": "error, FETCH returns 1, COMMIT and IDLE",
                "name": "recreated cursor can fetch",
                "observed": {
                  "error": true,
                  "row": [
                    1
                  ],
                  "status": "IDLE"
                },
                "passed": true
              }
            ],
            "case_id": "cursor_lifecycle_recovery",
            "cleanup": {
              "errors": [],
              "passed": true
            },
            "elapsed_seconds": 0.006,
            "observed": {
              "connection_autocommit": true,
              "diagnostic": {
                "column_name": null,
                "constraint_name": null,
                "context": null,
                "datatype_name": null,
                "exception_type": "InvalidCursorName",
                "internal_position": null,
                "internal_query": null,
                "message_detail": null,
                "message_hint": null,
                "message_primary": "cursor \"case_cursor_aa951a82\" does not exist",
                "schema_name": null,
                "severity": "ERROR",
                "severity_nonlocalized": "ERROR",
                "source_file": "portalcmds.c",
                "source_function": "PerformPortalFetch",
                "source_line": "199",
                "sqlstate": "34000",
                "statement_position": null,
                "table_name": null,
                "text": "cursor \"case_cursor_aa951a82\" does not exist"
              },
              "fetched_row": [
                1
              ],
              "session_scope": "The named cursor was declared, closed, and recreated on one backend session.",
              "statuses": {
                "after_error": "INERROR",
                "after_repair": "IDLE",
                "after_rollback": "IDLE"
              }
            },
            "schema": "c34000_cursor_lifecycle_recovery",
            "status": "passed"
          }
        ]
      }
    },
    {
      "id": "runtime.34000-batch34-20260909.pg10",
      "run_id": "34000-batch34-20260909",
      "target": "pg10",
      "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
      "status": "passed",
      "cases": [
        "cursor_lifecycle_recovery"
      ],
      "summary_sha256": "5c73ff2695864619e3771294e896ec2704bb4fae8e2b16d72aedf220063c2c6a",
      "raw_sha256": "1089cf85363624dcf5430744047b9dfde4760d763ebe10d5ed148047f9bb7c5c",
      "case_manifest": {
        "sha256": "72347c5c8f1ccfaa18aced582e9ff5bf0f968eff0547c9a8f6521ed7fa3adb47"
      },
      "observed": {
        "sqlstate": "34000",
        "primary": "cursor \"case_cursor_d0bb43e5\" does not exist",
        "severity": "ERROR",
        "statuses": {
          "after_error": "INERROR",
          "after_repair": "IDLE",
          "after_rollback": "IDLE"
        },
        "repair": {
          "fetched_row": [
            1
          ]
        },
        "connection_autocommit": true
      },
      "snippet_registry": {
        "sha256": "ad5b519e8ca30fd2636b1d0bace32dc18558cccc7b9d360081c27b12a1405f08"
      },
      "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",
            "digest": "sha256:b2baf8998630663d21370da06387c950e587071bdd307ee34e661cdcc7442bcc",
            "id": "sha256:b2baf8998630663d21370da06387c950e587071bdd307ee34e661cdcc7442bcc",
            "image": "postgres:10",
            "image_created": "2022-06-23T09:11:18.374607054Z",
            "image_ref": "postgres@sha256:b2baf8998630663d21370da06387c950e587071bdd307ee34e661cdcc7442bcc",
            "log_destination": "csvlog",
            "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": "34000",
                "name": "cursor sqlstate",
                "observed": "34000",
                "passed": true
              },
              {
                "expected": "cursor does not exist",
                "name": "missing cursor diagnostic",
                "observed": "cursor \"case_cursor_d0bb43e5\" does not exist",
                "passed": true
              },
              {
                "expected": "INERROR then IDLE",
                "name": "cursor error requires transaction recovery",
                "observed": {
                  "after_error": "INERROR",
                  "after_rollback": "IDLE"
                },
                "passed": true
              },
              {
                "expected": "error, FETCH returns 1, COMMIT and IDLE",
                "name": "recreated cursor can fetch",
                "observed": {
                  "error": true,
                  "row": [
                    1
                  ],
                  "status": "IDLE"
                },
                "passed": true
              }
            ],
            "case_id": "cursor_lifecycle_recovery",
            "cleanup": {
              "errors": [],
              "passed": true
            },
            "elapsed_seconds": 0.014,
            "observed": {
              "connection_autocommit": true,
              "diagnostic": {
                "column_name": null,
                "constraint_name": null,
                "context": null,
                "datatype_name": null,
                "exception_type": "InvalidCursorName",
                "internal_position": null,
                "internal_query": null,
                "message_detail": null,
                "message_hint": null,
                "message_primary": "cursor \"case_cursor_d0bb43e5\" does not exist",
                "schema_name": null,
                "severity": "ERROR",
                "severity_nonlocalized": "ERROR",
                "source_file": "portalcmds.c",
                "source_function": "PerformPortalFetch",
                "source_line": "195",
                "sqlstate": "34000",
                "statement_position": null,
                "table_name": null,
                "text": "cursor \"case_cursor_d0bb43e5\" does not exist"
              },
              "fetched_row": [
                1
              ],
              "session_scope": "The named cursor was declared, closed, and recreated on one backend session.",
              "statuses": {
                "after_error": "INERROR",
                "after_repair": "IDLE",
                "after_rollback": "IDLE"
              }
            },
            "schema": "c34000_cursor_lifecycle_recovery",
            "status": "passed"
          }
        ]
      }
    }
  ]
}
