kataras/iris · error

sqlx: bind: table: %q: %w

Error message

sqlx: bind: table: %q: %w

What it means

Schema.Bind fetches column metadata from the open *sql.Rows via src.ColumnTypes(); a failure there is wrapped as "sqlx: bind: table: <table>: %w" keeping the underlying driver error. It wraps only real driver/rows errors during the column-type lookup phase of Bind.

Source

Thrown at x/sqlx/sqlx.go:135

	if typ.Kind() != reflect.Ptr {
		return fmt.Errorf("sqlx: bind: destination not a pointer")
	}

	typ = typ.Elem()

	originalKind := typ.Kind()
	if typ.Kind() == reflect.Slice {
		typ = typ.Elem()
	}

	r, ok := s.Rows[typ]
	if !ok {
		return fmt.Errorf("sqlx: bind: unregistered type: %q", typ.String())
	}

	columnTypes, err := src.ColumnTypes()
	if err != nil {
		return fmt.Errorf("sqlx: bind: table: %q: %w", r.Name, err)
	}

	if expected, got := len(r.Columns), len(columnTypes); expected != got {
		return fmt.Errorf("sqlx: bind: table: %q: unexpected number of result columns: %d: expected: %d", r.Name, got, expected)
	}

	val := reflex.IndirectValue(reflect.ValueOf(dst))
	if s.AutoCloseRows {
		defer src.Close()
	}

	switch originalKind {
	case reflect.Struct:
		if src.Next() {
			if err = r.bindSingle(typ, val, columnTypes, src); err != nil {
				return err
			}
		} else {

View on GitHub (pinned to 7bedaf55a0)

Solutions

  1. Inspect the wrapped %w cause (use errors.Unwrap / errors.As) — fix the underlying driver error (network, closed rows, canceled context).
  2. Ensure the context is not canceled and the connection is alive before Query/Bind.
  3. Leave AutoCloseRows true (default) so rows are not closed before Bind reads ColumnTypes.

Example fix

// before
rows.Close()
schema.Bind(&user, rows) // wraps driver error
// after
if err := schema.Bind(&user, rows); err != nil {
    var derr *driver.Error
    if errors.As(err, &derr) { /* handle root cause */ }
}
Defensive patterns

Strategy: try-catch

Validate before calling

func rowsUsable(ctx context.Context, rows *sql.Rows) error {
	if rows == nil { return sql.ErrConnDone }
	if err := ctx.Err(); err != nil { return err }
	return nil
}

Try / catch

err := sqlx.Query(ctx, db, &user, q)
if err != nil && strings.HasPrefix(err.Error(), "sqlx: bind: table:") {
	cause := errors.Unwrap(err)
	log.Printf("bind failed for table, cause: %v", cause)
	// retry query with fresh context if cause is transient (net error / canceled ctx)
}

Prevention

When it happens

Trigger: Calling Bind/Query with rows whose connection dropped before ColumnTypes() is called, rows already closed (AutoCloseRows false and manually closed), or a driver that cannot report column metadata.

Common situations: Context cancellation/timeouts killing the query mid-flight; reusing rows after close; flaky connections under load.

Related errors


AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30). Data as JSON: /api/errors/21424ee8cadfda90. Report an issue: GitHub.