go
type_error
ai_generated
true
sql: 列索引 1 扫描错误:将 driver.Value 类型 []uint8 转换为 int64:无效转换
sql: Scan error on column index 1: converting driver.Value type []uint8 to int64: invalid conversion
ID: go/database-sql-scan-type-error
80%修复率
84%置信度
0证据数
2024-09-14首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.22 | active | — | — | — |
根因分析
将数据库值扫描到不兼容类型的 Go 变量中,例如将字符串列扫描为整数。
English
Scanning a database value into a Go variable of incompatible type, e.g., a string column into an integer.
解决方案
-
85% 成功率
var id int64; if err := rows.Scan(&id); err != nil { /* handle type mismatch */ }; // or scan into sql.NullString and convert
无效尝试
常见但无效的做法:
-
80% 失败
Fails at runtime if the value is not a string or []byte.
-
90% 失败
Leads to incorrect data handling and silent bugs.