jackc/pgx · error

expected arguments, got

Error message

expected %d arguments, got %d

What it means

The number of arguments passed to a query does not match the number of parameter OIDs ($1, $2, ...) reported by the server's statement description. The server expects len(sd.ParamOIDs) parameters but len(args) values were supplied.

Solutions

  1. Count the positional placeholders in the SQL and pass exactly that many arguments
  2. Check for accidentally passing a slice as a single argument instead of spreading it
  3. Verify the SQL string actually matches the arguments being bound
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at conn.go:826 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of jackc/pgx@ec1a0befd2 (2026-08-04). Data as JSON: /api/errors/32642c108e738433. Report an issue: GitHub.

Appendix: source

Thrown at conn.go:826

	}

	c.eqb.reset()
	rows := c.getRows(ctx, sql, args)

	var err error
	sd, explicitPreparedStatement := c.preparedStatements[sql]
	switch {
	case sd != nil || mode == QueryExecModeCacheStatement || mode == QueryExecModeCacheDescribe || mode == QueryExecModeDescribeExec:
		if sd == nil {
			sd, err = c.getStatementDescription(ctx, mode, sql)
			if err != nil {
				rows.fatal(err)
				return rows, err
			}
		}

		if len(sd.ParamOIDs) != len(args) {
			rows.fatal(fmt.Errorf("expected %d arguments, got %d", len(sd.ParamOIDs), len(args)))
			return rows, rows.err
		}

		rows.sql = sd.SQL

		err = c.eqb.Build(c.typeMap, sd, args)
		if err != nil {
			rows.fatal(err)
			return rows, rows.err
		}

		if resultFormatsByOID != nil {
			resultFormats = make([]int16, len(sd.Fields))
			for i := range resultFormats {
				resultFormats[i] = resultFormatsByOID[sd.Fields[i].DataTypeOID]
			}
		}

View on GitHub (pinned to ec1a0befd2)