# sql：列索引 2 上的 Scan 错误：不支持的 Scan，将 driver.Value 类型 <nil> 存储到 *time.Time 类型中

- **ID:** `go/unsupported-scan-type`
- **领域:** go
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

数据库为映射到非指针 Go 类型（如 time.Time）的列返回了 NULL 值，该类型无法表示 nil。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| go1.21 | active | — | — |
| go1.22 | active | — | — |
| go1.23 | active | — | — |

## 解决方案

1. ```
   Use a pointer type for the Go field, e.g., *time.Time instead of time.Time, to allow nil values.
   ```
2. ```
   Use sql.NullTime type from the database/sql package to handle nullable timestamps.
   ```

## 无效尝试

- **Changing the column type in the database to NOT NULL.** — This may break existing data or require schema migration; also not always under developer control. (50% 失败率)
- **Using a default value in the SQL query with COALESCE.** — COALESCE changes the query result but may mask missing data; also requires modifying every query. (40% 失败率)
