go data_error ai_generated true

sql: Scan error on column index 2: converting NULL to string is unsupported

ID: go/sql-nil-value-scan

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.13 active

Root Cause

数据库字段为NULL,但Scan目标类型不支持NULL

generic

中文

数据库字段为NULL,但Scan目标类型不支持NULL

Workarounds

  1. 95% success
    使用sql.NullString类型
  2. 85% success
    在SQL查询中使用COALESCE

Dead Ends

Common approaches that don't work:

  1. 90% fail

    NULL仍然无法转换为string

  2. 60% fail

    数据丢失