go data_error ai_generated true

error: sql: expected 2 arguments, got 3

ID: go/database-sql-query-arg-mismatch

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.20 active — — —

Root Cause

The number of placeholders in the SQL query does not match the number of arguments passed to Query or Exec.

generic

中文

SQL 查询中的占位符数量与传给 Query 或 Exec 的参数数量不匹配。

Workarounds

  1. 95% success
    Ensure the number of placeholders matches the number of arguments exactly.
  2. 90% success
    Use named parameters with sql.Named to avoid count mismatches.

Dead Ends

Common approaches that don't work:

  1. 80% fail

    This changes the query logic and may cause unintended results or errors.

  2. 90% fail

    The query will not execute, and subsequent operations may fail.