go data_error ai_generated true

错误:sql:期望2个参数,实际有3个

error: sql: expected 2 arguments, got 3

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

其他格式: JSON · Markdown 中文 · English
80%修复率
88%置信度
0证据数
2024-05-22首次发现

版本兼容性

版本状态引入弃用备注
1.20 active

根因分析

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

English

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

generic

解决方案

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

无效尝试

常见但无效的做法:

  1. 80% 失败

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

  2. 90% 失败

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