dgraph-io/dgraph · error
Compare not supported for type: %v
Error message
Compare not supported for type: %v
What it means
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.
Source
Thrown at types/sort.go:183
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))
case IntID:
return (a.Value.(int64)) < (b.Value.(int64))
case FloatID:
return (a.Value.(float64)) < (b.Value.(float64))
case UidID:
return (a.Value.(uint64) < b.Value.(uint64))
case StringID, DefaultID:View on GitHub (pinned to 759e242be6)
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
Example fix
// before
less, err := types.Less(a, b) // panics into error when b.Tid == BoolID
// after
if a.Tid == types.BoolID {
less = !a.Value.(bool) && b.Value.(bool)
} else {
less, err = types.Less(a, b)
} Defensive patterns
Strategy: type-guard
Validate before calling
switch a.Tid {
case types.BoolID, types.BinaryID:
return fmt.Errorf("type %s has no ordering", a.Tid)
}
ok, err := types.Less(a, b) Type guard
func orderable(v types.Val) bool {
switch v.Tid {
case types.DateTimeID, types.UidID, types.IntID, types.FloatID, types.StringID, types.DefaultID, types.BigFloatID:
return true
}
return false
} Try / catch
ok, err := types.Less(a, b)
if err != nil {
if strings.Contains(err.Error(), "Compare not supported") {
// fall back to type-specific comparison (e.g. bool XOR)
}
return err
} Prevention
- Exclude bool/binary predicates from generic sort pipelines
- Handle boolean ordering explicitly before calling Less
- Validate predicate schema types when building sort requests
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Value of type: %s isn't sortable
- Equal not supported for type: %v
- got unsupported type for list: %s
- Leaf predicate:'%v' must be a scalar.
- error interpreting appropriate type for %v
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/684ab52056b73044.
Report an issue: GitHub.