{"record":{"id":"909bce93fbf48122","repo":"kataras/iris","slug":"sqlx-bind-table-q-unexpected-destination-kind","errorCode":null,"errorMessage":"sqlx: bind: table: %q: unexpected destination kind: %q","messagePattern":"sqlx: bind: table: %q: unexpected destination kind: %q","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"x/sqlx/sqlx.go","lineNumber":175,"sourceCode":"\t\treturn src.Err()\n\tcase reflect.Slice:\n\t\tfor src.Next() {\n\t\t\telem := reflect.New(typ).Elem()\n\t\t\tif err = r.bindSingle(typ, elem, columnTypes, src); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\tval = reflect.Append(val, elem)\n\t\t}\n\n\t\tif err = src.Err(); err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\treflect.ValueOf(dst).Elem().Set(val)\n\t\treturn nil\n\tdefault:\n\t\treturn fmt.Errorf(\"sqlx: bind: table: %q: unexpected destination kind: %q\", r.Name, typ.Kind().String())\n\t}\n}\n\nfunc (r *Row) bindSingle(typ reflect.Type, val reflect.Value, columnTypes []*sql.ColumnType, scanner interface{ Scan(...any) error }) error {\n\tfieldPtrs, err := r.lookupStructFieldPtrs(typ, val, columnTypes)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"sqlx: bind: table: %q: %w\", r.Name, err)\n\t}\n\n\treturn scanner.Scan(fieldPtrs...)\n}\n\nfunc (r *Row) lookupStructFieldPtrs(typ reflect.Type, val reflect.Value, columnTypes []*sql.ColumnType) ([]any, error) {\n\tfieldPtrs := make([]any, 0, len(columnTypes))\n\n\tfor _, columnType := range columnTypes {\n\t\tcolumnName := columnType.Name()\n\t\ttableColumn, ok := r.Columns[columnName]","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/x/sqlx/sqlx.go#L157-L193","documentation":"Bind maps query results into a destination via reflection and supports only specific destination kinds (pointer-to-struct, pointer-to-slice-of-struct, and similar scan targets). Passing a dst whose reflected kind falls outside the switch's handled cases hits the default branch and returns this error. It is a programmer-API misuse, not a data problem.","triggerScenarios":"Passing a non-pointer, a pointer to a map, a pointer to a primitive (e.g. *int where a struct/slice is expected), or a **struct (double pointer) as dst to Query/Bind.","commonSituations":"Copying code from database/sql style scans into sqlx Bind; accidentally passing &userSlice where userSlice is already a pointer; passing nil interface.","solutions":["Pass a *Struct or *[]Struct as dst","Dereference double pointers before calling","Check that dst is not nil","If scanning a scalar, use the raw database/sql Rows.Scan instead of Bind"],"exampleFix":"// before\nvar user *User\nerr := db.Query(row, &user, \"SELECT ...\")\n// after\nvar user User\nerr := db.Query(row, &user, \"SELECT ...\")","handlingStrategy":"type-guard","validationCode":"if dst == nil || reflect.TypeOf(dst).Kind() != reflect.Ptr { return errors.New(\"dst must be a pointer to struct or slice\") }","typeGuard":"func isBindableDst(dst any) bool {\n\tt := reflect.TypeOf(dst)\n\tif t == nil || t.Kind() != reflect.Ptr { return false }\n\te := t.Elem()\n\treturn e.Kind() == reflect.Struct || e.Kind() == reflect.Slice\n}","tryCatchPattern":"if err := db.Query(row, dst, q); err != nil { if strings.Contains(err.Error(), \"unexpected destination kind\") { return fmt.Errorf(\"bad dst %T: %w\", dst, err) } return err }","preventionTips":["Always pass &struct or &[]struct","Avoid double pointers and pre-declared pointer variables","Add unit tests covering each destination shape"],"tags":["reflection","api-misuse","go"],"backgroundTag":"invalid-destination-type","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}