dgraph-io/dgraph · error
Arguments of different type can not be compared.
Error message
Arguments of different type can not be compared.
What it means
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.
Source
Thrown at types/sort.go:176
cl = collate.New(langTag)
}
}
b := sortBase{v, desc, ul, l, cl}
toBeSorted := byValue{b}
sort.Sort(toBeSorted)
return nil
}
// Sort sorts the given array in-place.
func Sort(v [][]Val, ul *[]uint64, desc []bool, lang string) error {
return SortWithFacet(v, ul, nil, desc, lang)
}
// Less returns true if a is strictly less than b.
func Less(a, b Val) (bool, error) {
if a.Tid != b.Tid {
return false, errors.Errorf("Arguments of different type can not be compared.")
}
typ := a.Tid
switch typ {
case DateTimeID, UidID, IntID, FloatID, StringID, DefaultID, BigFloatID:
// Don't do anything, we can sort values of this type.
default:
return false, errors.Errorf("Compare not supported for type: %v", a.Tid)
}
return less(a, b, nil), nil
}
func less(a, b Val, cl *collate.Collator) bool {
if a.Tid != b.Tid {
return mismatchedLess(a, b)
}
switch a.Tid {
case DateTimeID:
return a.Value.(time.Time).Before(b.Value.(time.Time))View on GitHub (pinned to 759e242be6)
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
Example fix
// before
ok, err := types.Less(types.Val{Tid: types.IntID, Value: int64(3)}, types.Val{Tid: types.FloatID, Value: 3.5}) // error
// after
a := types.Val{Tid: types.FloatID, Value: float64(3)}
b := types.Val{Tid: types.FloatID, Value: 3.5}
ok, err := types.Less(a, b) Defensive patterns
Strategy: type-guard
Validate before calling
if a.Tid != b.Tid {
return fmt.Errorf("cannot compare %s with %s", a.Tid.Name(), b.Tid.Name())
}
ok, err := types.Less(a, b) Type guard
func sameType(a, b types.Val) bool { return a.Tid == b.Tid } Try / catch
ok, err := types.Less(a, b)
if err != nil {
if strings.Contains(err.Error(), "different type") {
// coerce both to a common Tid and retry
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Leaf predicate:'%v' must be a scalar.
- error interpreting appropriate type for %v
- while fetching types
- Value of type: %s isn't sortable
- Compare not supported for type: %v
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/2aaa08a2f5a94f1b.
Report an issue: GitHub.