{"record":{"id":"2aaa08a2f5a94f1b","repo":"dgraph-io/dgraph","slug":"arguments-of-different-type-can-not-be-compared","errorCode":null,"errorMessage":"Arguments of different type can not be compared.","messagePattern":"Arguments of different type can not be compared\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"types/sort.go","lineNumber":176,"sourceCode":"\t\t\tcl = collate.New(langTag)\n\t\t}\n\t}\n\n\tb := sortBase{v, desc, ul, l, cl}\n\ttoBeSorted := byValue{b}\n\tsort.Sort(toBeSorted)\n\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))","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/types/sort.go#L158-L194","documentation":"types.Less compares two Val values and only works when both operands share the exact same TypeID. Dgraph refuses to define an ordering across different types, so if a.Tid != b.Tid it returns this error instead of guessing a comparison.","triggerScenarios":"Calling types.Less(a, b) where a and b carry different TypeIDs — e.g. comparing an IntID value to a FloatID value, or a StringID to a DateTimeID. Also reachable via callers that feed heterogeneous Val slices into sorting/pagination built on Less.","commonSituations":"Comparing values read from two predicates with different scalar schemas (int vs float); comparing a string coerced value against a native typed value; bug in code that builds Val structs without normalizing Tid.","solutions":["Coerce both values to the same type (e.g. convert int64 to float64) before calling Less","Verify the schema of the predicates involved and ensure both sides come from the same type","Check that Val.Tid was set correctly when constructing the values","Use Equal/CompareVals only on values from the same attribute type"],"exampleFix":"// before\nok, err := types.Less(types.Val{Tid: types.IntID, Value: int64(3)}, types.Val{Tid: types.FloatID, Value: 3.5}) // error\n// after\na := types.Val{Tid: types.FloatID, Value: float64(3)}\nb := types.Val{Tid: types.FloatID, Value: 3.5}\nok, err := types.Less(a, b)","handlingStrategy":"type-guard","validationCode":"if a.Tid != b.Tid {\n    return fmt.Errorf(\"cannot compare %s with %s\", a.Tid.Name(), b.Tid.Name())\n}\nok, err := types.Less(a, b)","typeGuard":"func sameType(a, b types.Val) bool { return a.Tid == b.Tid }","tryCatchPattern":"ok, err := types.Less(a, b)\nif err != nil {\n    if strings.Contains(err.Error(), \"different type\") {\n        // coerce both to a common Tid and retry\n    }\n    return err\n}","preventionTips":["Convert operands to a common type (types.Convert) before comparison","Ensure both values originate from predicates with the same scalar schema","Never mix int64 and float64 Vals without normalizing Tid"],"tags":["comparison","types","dgraph"],"backgroundTag":"comparison-type-mismatch","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}