{
  "schema": 1,
  "sqlstate": "P0001",
  "condition_name": "raise_exception",
  "runner": "scripts/verify_cases.py",
  "targets": {
    "latest": {
      "binary": "Homebrew PostgreSQL 18.6",
      "required": true
    },
    "pg10": {
      "image": "postgres:10",
      "required": true
    }
  },
  "cases": [
    {
      "id": "plpgsql_raise_exception",
      "versions": [
        "10",
        "18"
      ],
      "preconditions": [
        "PL/pgSQL is available"
      ],
      "trigger": "Execute a function containing RAISE EXCEPTION without an explicit SQLSTATE.",
      "assertions": [
        "SQLSTATE is P0001",
        "The custom message is preserved",
        "The failed call is isolated to its transaction"
      ],
      "repair": "Use a domain-specific SQLSTATE only when the caller contract requires it; catch and handle the exception at the correct transaction boundary.",
      "cleanup": "Drop the function and case schema."
    }
  ],
  "evidence_status": "authored",
  "snippets": [
    {
      "id": "plpgsql_raise_exception",
      "case_id": "plpgsql_raise_exception",
      "language": "sql",
      "statements": {
        "function": "CREATE FUNCTION raise_exception_case() RETURNS void\nLANGUAGE plpgsql AS $$\nBEGIN\n    RAISE EXCEPTION 'calibration exception';\nEND\n$$",
        "call": "SELECT raise_exception_case()",
        "followup": "SELECT 1"
      }
    }
  ],
  "runtime": [
    {
      "cases": [
        "plpgsql_raise_exception"
      ],
      "id": "runtime.P0001-snippet-registry-final-20260909.latest",
      "observed": {
        "followup": 1,
        "message_primary": "calibration exception",
        "severity": "ERROR",
        "source_file": "pl_exec.c",
        "source_function": "exec_stmt_raise",
        "source_line": "3923",
        "sqlstate": "P0001",
        "status_after_error": "IDLE"
      },
      "raw_sha256": "f0ce5f0fcbeaeba978fbb959a418c24eac2ec1db2b0393b9bc15f24d3936ed1b",
      "run_id": "P0001-snippet-registry-final-20260909",
      "server_version": "18.6 (Homebrew)",
      "server_version_num": 180006,
      "snippet_registry": {
        "sha256": "1728525c9f6f073807ce34df0d9a4ee60f1c8bce5179c8bca91c92ca79aa795a"
      },
      "status": "passed",
      "summary_sha256": "6c298799062a8c47fd2eee07194afc0a6e53d7e1ef87639c9f996951f4de3c9b",
      "target": "latest",
      "result": {
        "status": "passed",
        "environment": {
          "TimeZone": "Asia/Shanghai",
          "backend_pid": 11329,
          "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": "P0001",
                "name": "raise-exception sqlstate",
                "observed": "P0001",
                "passed": true
              },
              {
                "expected": "calibration exception",
                "name": "custom message is preserved",
                "observed": "calibration exception",
                "passed": true
              },
              {
                "expected": "error, IDLE, SELECT 1",
                "name": "autocommit remains usable",
                "observed": {
                  "error": true,
                  "followup": 1,
                  "status": "IDLE"
                },
                "passed": true
              }
            ],
            "case_id": "plpgsql_raise_exception",
            "cleanup": {
              "errors": [],
              "passed": true
            },
            "elapsed_seconds": 0.029,
            "observed": {
              "diagnostic": {
                "column_name": null,
                "constraint_name": null,
                "context": "PL/pgSQL function cp0001_plpgsql_raise_exception.raise_exception_case() line 3 at RAISE",
                "datatype_name": null,
                "exception_type": "RaiseException",
                "internal_position": null,
                "internal_query": null,
                "message_detail": null,
                "message_hint": null,
                "message_primary": "calibration exception",
                "schema_name": null,
                "severity": "ERROR",
                "severity_nonlocalized": "ERROR",
                "source_file": "pl_exec.c",
                "source_function": "exec_stmt_raise",
                "source_line": "3923",
                "sqlstate": "P0001",
                "statement_position": null,
                "table_name": null,
                "text": "calibration exception\nCONTEXT:  PL/pgSQL function cp0001_plpgsql_raise_exception.raise_exception_case() line 3 at RAISE"
              },
              "followup": 1,
              "status": "IDLE"
            },
            "schema": "cp0001_plpgsql_raise_exception",
            "status": "passed"
          }
        ]
      }
    },
    {
      "cases": [
        "plpgsql_raise_exception"
      ],
      "id": "runtime.P0001-snippet-registry-final-20260909.pg10",
      "image": "postgres@sha256:b2baf8998630663d21370da06387c950e587071bdd307ee34e661cdcc7442bcc",
      "observed": {
        "followup": 1,
        "message_primary": "calibration exception",
        "severity": "ERROR",
        "source_file": "pl_exec.c",
        "source_function": "exec_stmt_raise",
        "source_line": "3337",
        "sqlstate": "P0001",
        "status_after_error": "IDLE"
      },
      "raw_sha256": "4308e016521aed455b575094b061162077e06f83884e53e96074db1d7b144dac",
      "run_id": "P0001-snippet-registry-final-20260909",
      "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
      "server_version_num": 100021,
      "snippet_registry": {
        "sha256": "1728525c9f6f073807ce34df0d9a4ee60f1c8bce5179c8bca91c92ca79aa795a"
      },
      "status": "passed",
      "summary_sha256": "5fe9b2e2a9147aebe3bd43af67cd60ff768dddbbe10ae92bb0a5a6d9dcad230c",
      "target": "pg10",
      "result": {
        "status": "passed",
        "environment": {
          "TimeZone": "Etc/UTC",
          "backend_pid": 78,
          "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": "P0001",
                "name": "raise-exception sqlstate",
                "observed": "P0001",
                "passed": true
              },
              {
                "expected": "calibration exception",
                "name": "custom message is preserved",
                "observed": "calibration exception",
                "passed": true
              },
              {
                "expected": "error, IDLE, SELECT 1",
                "name": "autocommit remains usable",
                "observed": {
                  "error": true,
                  "followup": 1,
                  "status": "IDLE"
                },
                "passed": true
              }
            ],
            "case_id": "plpgsql_raise_exception",
            "cleanup": {
              "errors": [],
              "passed": true
            },
            "elapsed_seconds": 0.039,
            "observed": {
              "diagnostic": {
                "column_name": null,
                "constraint_name": null,
                "context": "PL/pgSQL function cp0001_plpgsql_raise_exception.raise_exception_case() line 3 at RAISE",
                "datatype_name": null,
                "exception_type": "RaiseException",
                "internal_position": null,
                "internal_query": null,
                "message_detail": null,
                "message_hint": null,
                "message_primary": "calibration exception",
                "schema_name": null,
                "severity": "ERROR",
                "severity_nonlocalized": "ERROR",
                "source_file": "pl_exec.c",
                "source_function": "exec_stmt_raise",
                "source_line": "3337",
                "sqlstate": "P0001",
                "statement_position": null,
                "table_name": null,
                "text": "calibration exception\nCONTEXT:  PL/pgSQL function cp0001_plpgsql_raise_exception.raise_exception_case() line 3 at RAISE"
              },
              "followup": 1,
              "status": "IDLE"
            },
            "schema": "cp0001_plpgsql_raise_exception",
            "status": "passed"
          }
        ]
      }
    }
  ]
}
