go
type_error
ai_generated
true
错误:sql:列索引0上的扫描错误:不支持的扫描,将driver.Value类型int64存储到*string类型
error: sql: Scan error on column index 0: unsupported Scan, storing driver.Value type int64 into type *string
ID: go/database-sql-rows-scan-type-mismatch
80%修复率
87%置信度
0证据数
2025-02-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.20 | active | — | — | — |
| 1.21 | active | — | — | — |
根因分析
将数据库列扫描到不兼容类型的Go变量中,例如将整数扫描到字符串指针。
English
Scanning a database column into a Go variable of incompatible type, e.g., scanning an integer into a string pointer.
解决方案
-
90% 成功率 Use sql.NullString or appropriate types
var name sql.NullString if err := rows.Scan(&name); err != nil { return err } if name.Valid { /* use name.String */ }
无效尝试
常见但无效的做法:
-
Using fmt.Sprintf to convert values manually
60% 失败
Inefficient and error-prone; use proper type mapping.