{"record":{"id":"f8329f5489bebf1d","repo":"kataras/iris","slug":"sqlx-bind-unregistered-type-q","errorCode":null,"errorMessage":"sqlx: bind: unregistered type: %q","messagePattern":"sqlx: bind: unregistered type: %q","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"x/sqlx/sqlx.go","lineNumber":130,"sourceCode":"}\n\n// Bind sets \"dst\" to the result of \"src\" and reports any errors.\nfunc (s *Schema) Bind(dst any, src *sql.Rows) error {\n\ttyp := reflect.TypeOf(dst)\n\tif typ.Kind() != reflect.Ptr {\n\t\treturn fmt.Errorf(\"sqlx: bind: destination not a pointer\")\n\t}\n\n\ttyp = typ.Elem()\n\n\toriginalKind := typ.Kind()\n\tif typ.Kind() == reflect.Slice {\n\t\ttyp = typ.Elem()\n\t}\n\n\tr, ok := s.Rows[typ]\n\tif !ok {\n\t\treturn fmt.Errorf(\"sqlx: bind: unregistered type: %q\", typ.String())\n\t}\n\n\tcolumnTypes, err := src.ColumnTypes()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"sqlx: bind: table: %q: %w\", r.Name, err)\n\t}\n\n\tif expected, got := len(r.Columns), len(columnTypes); expected != got {\n\t\treturn fmt.Errorf(\"sqlx: bind: table: %q: unexpected number of result columns: %d: expected: %d\", r.Name, got, expected)\n\t}\n\n\tval := reflex.IndirectValue(reflect.ValueOf(dst))\n\tif s.AutoCloseRows {\n\t\tdefer src.Close()\n\t}\n\n\tswitch originalKind {\n\tcase reflect.Struct:","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/x/sqlx/sqlx.go#L112-L148","documentation":"Schema.Bind looks up the element type of dst in Schema.Rows, a registry populated by Register(tableName, value). If the struct type (or slice element type) was never registered, Bind cannot know the table/column mapping and returns \"sqlx: bind: unregistered type: %q\" with the Go type name.","triggerScenarios":"sqlx.Query(ctx, db, &Order{}, ...) without a prior sqlx.Register(\"orders\", Order{}) or schema.Register for that exact type; registering the type on a different Schema instance than the one used for Query.","commonSituations":"Forgot the init-time Register call; registered a renamed/aliased struct while querying the original; using DefaultSchema via sqlx.Register but querying a custom NewSchema().","solutions":["Register the type before querying: sqlx.Register(\"orders\", Order{}) (or s.Register on the same Schema used by Bind).","Ensure the destination element type exactly matches the registered type (same package/name).","If you use a custom NewSchema, call Register on that schema, not the package-level DefaultSchema."],"exampleFix":"// before\nsqlx.Query(ctx, db, &order, \"SELECT * FROM orders\") // unregistered\n// after\nsqlx.Register(\"orders\", Order{})\nsqlx.Query(ctx, db, &order, \"SELECT * FROM orders\")","handlingStrategy":"validation","validationCode":"func ensureRegistered(s *sqlx.Schema, dst any) error {\n\ttyp := reflect.TypeOf(dst)\n\tfor typ.Kind() == reflect.Ptr { typ = typ.Elem() }\n\tif typ.Kind() == reflect.Slice { typ = typ.Elem() }\n\tif _, ok := s.Rows[typ]; !ok {\n\t\treturn fmt.Errorf(\"type %s not registered; call Register first\", typ)\n\t}\n\treturn nil\n}","typeGuard":"func isRegistered(s *sqlx.Schema, dst any) bool {\n\ttyp := reflect.TypeOf(dst)\n\tfor typ.Kind() == reflect.Ptr { typ = typ.Elem() }\n\tif typ.Kind() == reflect.Slice { typ = typ.Elem() }\n\t_, ok := s.Rows[typ]\n\treturn ok\n}","tryCatchPattern":"if err := sqlx.Query(ctx, db, &order, q); err != nil {\n\tif strings.Contains(err.Error(), \"unregistered type\") {\n\t\tsqlx.Register(\"orders\", Order{})\n\t\terr = sqlx.Query(ctx, db, &order, q)\n\t}\n\treturn err\n}","preventionTips":["Register every struct at startup near DB initialization","Use the same Schema instance for Register and Query/Bind","Add a test asserting each queried type is registered"],"tags":["go","sql","sqlx","bind","registration"],"backgroundTag":"unregistered-type","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}