go
data_error
ai_generated
true
sql: Scan error on column index 1: converting driver.Value type []uint8 ("123") to a int64: invalid syntax
ID: go/sql-scan-type-mismatch
80%Fix Rate
86%Confidence
0Evidence
2024-06-18First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.21 | active | — | — | — |
Root Cause
Database returns a string representation of a number, but target is int; conversion fails.
generic中文
数据库返回数字的字符串表示,但目标类型是 int,转换失败。
Workarounds
-
95% success
Scan into a string first, then parse: var s string; rows.Scan(&s); num, _ := strconv.Atoi(s)
-
90% success
Use sql.NullInt64 and handle invalid: var n sql.NullInt64; rows.Scan(&n); if n.Valid { use n.Int64 }
Dead Ends
Common approaches that don't work:
-
40% fail
May not be possible or desirable; schema changes risky.
-
90% fail
Data loss; incorrect results.