{
  "schema": 1,
  "sqlstate": "22012",
  "condition_name": "division_by_zero",
  "runner": "scripts/verify_cases.py",
  "targets": {
    "latest": {
      "binary": "Homebrew PostgreSQL 18.6",
      "required": true
    },
    "pg10": {
      "image": "postgres:10",
      "required": true
    }
  },
  "cases": [
    {
      "id": "division_by_zero_numeric",
      "versions": [
        "10",
        "18"
      ],
      "preconditions": [
        "A runner-owned disposable target is provisioned."
      ],
      "trigger": "Evaluate a numeric expression with a zero denominator.",
      "assertions": [
        "SQLSTATE is 22012 with primary division by zero",
        "The failed autocommit session remains IDLE",
        "A nonzero denominator returns the defined numeric result"
      ],
      "repair": "Validate the denominator or apply an explicitly chosen domain policy; do not silently turn a calculation into NULL with NULLIF unless that is the intended business result.",
      "cleanup": "Close the runner connection and drop the case schema with an owner connection."
    }
  ],
  "evidence_status": "authored",
  "snippets": [
    {
      "id": "division_by_zero_numeric",
      "case_id": "division_by_zero_numeric",
      "language": "sql",
      "statements": {
        "trigger": "SELECT 10::numeric / 0::numeric",
        "repair": "SELECT 10::numeric / 2::numeric"
      }
    }
  ],
  "runtime": [
    {
      "id": "runtime.22012-data-runtime-latest.latest",
      "run_id": "22012-data-runtime-latest",
      "target": "latest",
      "server_version": "18.6 (Homebrew)",
      "server_version_num": 180006,
      "status": "passed",
      "cases": [
        "division_by_zero_numeric"
      ],
      "summary_sha256": "a92ed17a37d32b0a6dc3f30c2b900f4d643fa0dea2736110b1d6170ccba4157c",
      "raw_sha256": "9d7035f924444adf1fa68308787310083c584343376d7b041e803a3bd2e1b539",
      "snippet_registry": {
        "sha256": "d070ef39a492c0411c3fc2cf9cc841321cae85cbd8a2f8d169f49ecbadbd3be7"
      },
      "observed": {
        "sqlstate": "22012",
        "status_after_repair": "IDLE"
      },
      "result": {
        "status": "passed",
        "environment": {
          "TimeZone": "Asia/Shanghai",
          "backend_pid": 21218,
          "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": "22012",
                "name": "22012 SQLSTATE",
                "observed": "22012",
                "passed": true
              },
              {
                "expected": "ERROR",
                "name": "22012 ERROR severity",
                "observed": "ERROR",
                "passed": true
              },
              {
                "expected": "division by zero",
                "name": "22012 primary diagnostic",
                "observed": "division by zero",
                "passed": true
              },
              {
                "expected": "IDLE",
                "name": "division error leaves session usable",
                "observed": "IDLE",
                "passed": true
              },
              {
                "expected": {
                  "status": "IDLE",
                  "value": 5
                },
                "name": "nonzero denominator repairs numeric calculation",
                "observed": {
                  "status": "IDLE",
                  "value": "5.0000000000000000"
                },
                "passed": true
              }
            ],
            "case_id": "division_by_zero_numeric",
            "cleanup": {
              "errors": [],
              "passed": true
            },
            "elapsed_seconds": 0.007,
            "observed": {
              "connection_autocommit": true,
              "diagnostic": {
                "column_name": null,
                "constraint_name": null,
                "context": null,
                "datatype_name": null,
                "exception_type": "DivisionByZero",
                "internal_position": null,
                "internal_query": null,
                "message_detail": null,
                "message_hint": null,
                "message_primary": "division by zero",
                "schema_name": null,
                "severity": "ERROR",
                "severity_nonlocalized": "ERROR",
                "source_file": "numeric.c",
                "source_function": "div_var",
                "source_line": "9438",
                "sqlstate": "22012",
                "statement_position": null,
                "table_name": null,
                "text": "division by zero"
              },
              "failed_status": "IDLE",
              "repair_status": "IDLE",
              "repair_value": "5.0000000000000000"
            },
            "schema": "c22012_division_by_zero_numeric",
            "status": "passed"
          }
        ]
      }
    },
    {
      "id": "runtime.22012-data-runtime-pg10.pg10",
      "run_id": "22012-data-runtime-pg10",
      "target": "pg10",
      "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
      "server_version_num": 100021,
      "status": "passed",
      "cases": [
        "division_by_zero_numeric"
      ],
      "summary_sha256": "60991b51352ba0c2294f65719ada02e39aba969e7467755b138febedcd548e50",
      "raw_sha256": "e8b465904879a89b453d291d4cabddcfe8920ea8c9752f83213644e84f6510f2",
      "snippet_registry": {
        "sha256": "d070ef39a492c0411c3fc2cf9cc841321cae85cbd8a2f8d169f49ecbadbd3be7"
      },
      "observed": {
        "sqlstate": "22012",
        "status_after_repair": "IDLE"
      },
      "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": "22012",
                "name": "22012 SQLSTATE",
                "observed": "22012",
                "passed": true
              },
              {
                "expected": "ERROR",
                "name": "22012 ERROR severity",
                "observed": "ERROR",
                "passed": true
              },
              {
                "expected": "division by zero",
                "name": "22012 primary diagnostic",
                "observed": "division by zero",
                "passed": true
              },
              {
                "expected": "IDLE",
                "name": "division error leaves session usable",
                "observed": "IDLE",
                "passed": true
              },
              {
                "expected": {
                  "status": "IDLE",
                  "value": 5
                },
                "name": "nonzero denominator repairs numeric calculation",
                "observed": {
                  "status": "IDLE",
                  "value": "5.0000000000000000"
                },
                "passed": true
              }
            ],
            "case_id": "division_by_zero_numeric",
            "cleanup": {
              "errors": [],
              "passed": true
            },
            "elapsed_seconds": 0.01,
            "observed": {
              "connection_autocommit": true,
              "diagnostic": {
                "column_name": null,
                "constraint_name": null,
                "context": null,
                "datatype_name": null,
                "exception_type": "DivisionByZero",
                "internal_position": null,
                "internal_query": null,
                "message_detail": null,
                "message_hint": null,
                "message_primary": "division by zero",
                "schema_name": null,
                "severity": "ERROR",
                "severity_nonlocalized": "ERROR",
                "source_file": "numeric.c",
                "source_function": "div_var",
                "source_line": "6891",
                "sqlstate": "22012",
                "statement_position": null,
                "table_name": null,
                "text": "division by zero"
              },
              "failed_status": "IDLE",
              "repair_status": "IDLE",
              "repair_value": "5.0000000000000000"
            },
            "schema": "c22012_division_by_zero_numeric",
            "status": "passed"
          }
        ]
      }
    }
  ]
}
