go
data_error
ai_generated
true
sql: Scan error on column index 2, name "email": converting NULL to string is unsupported
ID: go/sql-converting-null-to-string
80%Fix Rate
89%Confidence
0Evidence
2024-03-04First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.18 | active | — | — | — |
| 1.21 | active | — | — | — |
Root Cause
A nullable column was scanned into a non-pointer string. NULL cannot be assigned to string.
generic中文
向非指针 string 扫描可空列。NULL 无法赋给 string。
Workarounds
-
92% success
var email sql.NullString err := row.Scan(&email) if email.Valid { u.Email = email.String } -
88% success
Use a pointer *string for nullable columns.
Dead Ends
Common approaches that don't work:
-
60% fail
Loses the distinction between empty and NULL.
-
65% fail
Requires type assertion and is error-prone.