go
type_error
ai_generated
true
sql: Scan error on column index 1: converting driver.Value type []uint8 to int64: invalid conversion
ID: go/database-sql-scan-type-error
80%Fix Rate
84%Confidence
0Evidence
2024-09-14First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.22 | active | — | — | — |
Root Cause
Scanning a database value into a Go variable of incompatible type, e.g., a string column into an integer.
generic中文
将数据库值扫描到不兼容类型的 Go 变量中,例如将字符串列扫描为整数。
Workarounds
-
85% success
var id int64; if err := rows.Scan(&id); err != nil { /* handle type mismatch */ }; // or scan into sql.NullString and convert
Dead Ends
Common approaches that don't work:
-
80% fail
Fails at runtime if the value is not a string or []byte.
-
90% fail
Leads to incorrect data handling and silent bugs.