{"record":{"id":"684ab52056b73044","repo":"dgraph-io/dgraph","slug":"compare-not-supported-for-type-v","errorCode":null,"errorMessage":"Compare not supported for type: %v","messagePattern":"Compare not supported for type: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"types/sort.go","lineNumber":183,"sourceCode":"\treturn nil\n}\n\n// Sort sorts the given array in-place.\nfunc Sort(v [][]Val, ul *[]uint64, desc []bool, lang string) error {\n\treturn SortWithFacet(v, ul, nil, desc, lang)\n}\n\n// Less returns true if a is strictly less than b.\nfunc Less(a, b Val) (bool, error) {\n\tif a.Tid != b.Tid {\n\t\treturn false, errors.Errorf(\"Arguments of different type can not be compared.\")\n\t}\n\ttyp := a.Tid\n\tswitch typ {\n\tcase DateTimeID, UidID, IntID, FloatID, StringID, DefaultID, BigFloatID:\n\t\t// Don't do anything, we can sort values of this type.\n\tdefault:\n\t\treturn false, errors.Errorf(\"Compare not supported for type: %v\", a.Tid)\n\t}\n\treturn less(a, b, nil), nil\n}\n\nfunc less(a, b Val, cl *collate.Collator) bool {\n\tif a.Tid != b.Tid {\n\t\treturn mismatchedLess(a, b)\n\t}\n\tswitch a.Tid {\n\tcase DateTimeID:\n\t\treturn a.Value.(time.Time).Before(b.Value.(time.Time))\n\tcase IntID:\n\t\treturn (a.Value.(int64)) < (b.Value.(int64))\n\tcase FloatID:\n\t\treturn (a.Value.(float64)) < (b.Value.(float64))\n\tcase UidID:\n\t\treturn (a.Value.(uint64) < b.Value.(uint64))\n\tcase StringID, DefaultID:","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/types/sort.go#L165-L201","documentation":"After confirming both Vals share a type, types.Less switches on that TypeID and only supports ordering for DateTime, Uid, Int, Float, String, Default and BigFloat. Any other type (bool, binary, etc.) reaches the default branch and yields this error, since those types have no defined ordering.","triggerScenarios":"Calling types.Less on two same-typed Vals whose Tid is a non-orderable type such as BoolID or BinaryID — typically sorting or paginating on a bool predicate's values.","commonSituations":"Attempting to sort query results on a boolean predicate; sorting encrypted/binary values; code that generically sorts results without filtering out bool/binary attributes first.","solutions":["Filter out predicates with non-orderable types (bool, binary) before sorting","Sort bools client-side with a simple boolean comparison instead of types.Less","Change the schema type of the predicate to an orderable scalar if ordering is required","Add an explicit Tid switch in your code to handle BoolID before delegating to Less"],"exampleFix":"// before\nless, err := types.Less(a, b) // panics into error when b.Tid == BoolID\n// after\nif a.Tid == types.BoolID {\n    less = !a.Value.(bool) && b.Value.(bool)\n} else {\n    less, err = types.Less(a, b)\n}","handlingStrategy":"type-guard","validationCode":"switch a.Tid {\ncase types.BoolID, types.BinaryID:\n    return fmt.Errorf(\"type %s has no ordering\", a.Tid)\n}\nok, err := types.Less(a, b)","typeGuard":"func orderable(v types.Val) bool {\n    switch v.Tid {\n    case types.DateTimeID, types.UidID, types.IntID, types.FloatID, types.StringID, types.DefaultID, types.BigFloatID:\n        return true\n    }\n    return false\n}","tryCatchPattern":"ok, err := types.Less(a, b)\nif err != nil {\n    if strings.Contains(err.Error(), \"Compare not supported\") {\n        // fall back to type-specific comparison (e.g. bool XOR)\n    }\n    return err\n}","preventionTips":["Exclude bool/binary predicates from generic sort pipelines","Handle boolean ordering explicitly before calling Less","Validate predicate schema types when building sort requests"],"tags":["sorting","types","unsupported-type","dgraph"],"backgroundTag":"unsupported-operation-for-type","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}