go data_error ai_generated true

error: sql: expected 0 columns, got 3

ID: go/database-sql-query-row-without-scan

Also available as: JSON · Markdown · 中文
80%Fix Rate
88%Confidence
0Evidence
2024-01-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.20 active
1.21 active

Root Cause

Using QueryRow without scanning the result, leaving rows unclosed and causing resource leak.

generic

中文

使用QueryRow而不扫描结果,导致行未关闭并造成资源泄漏。

Workarounds

  1. 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:

  1. Calling QueryRow and ignoring result 80% fail

    Rows remain open; always scan or call Close.