go data_error ai_generated true

sql: Scan error on column index 1: converting driver.Value type []uint8 ("123") to a int: invalid syntax

ID: go/database-sql-rows-scan-type-error

Also available as: JSON · Markdown · 中文
80%Fix Rate
84%Confidence
0Evidence
2024-05-30First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.20 active

Root Cause

The database driver returned a type that cannot be directly converted to the destination Go type in Scan.

generic

中文

数据库驱动返回的类型无法直接转换为Scan中的目标Go类型。

Workarounds

  1. 90% success
    Use sql.NullInt64 or specify the correct type in the SELECT query, e.g., CAST(column AS SIGNED).

Dead Ends

Common approaches that don't work:

  1. 50% fail

    May lose numeric precision or cause type mismatches in downstream code.

  2. 60% fail

    Clunky and error-prone; may not handle all types correctly.