go
data_error
ai_generated
true
error: sql: expected 0 columns, got 3
ID: go/database-sql-query-row-without-scan
80%Fix Rate
88%Confidence
0Evidence
2024-01-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.20 | active | — | — | — |
| 1.21 | active | — | — | — |
Root Cause
Using QueryRow without scanning the result, leaving rows unclosed and causing resource leak.
generic中文
使用QueryRow而不扫描结果,导致行未关闭并造成资源泄漏。
Workarounds
-
98% success Always scan the result of QueryRow
row := db.QueryRowContext(ctx, "SELECT name FROM users WHERE id = ?", id) var name string if err := row.Scan(&name); err != nil { return err }
Dead Ends
Common approaches that don't work:
-
Calling QueryRow and ignoring result
80% fail
Rows remain open; always scan or call Close.