dgraph-io/dgraph · error

Invalid compare function %q

Error message

Invalid compare function %q

What it means

compareValues returns this error when the comparison operator (ag) supplied to a filter/aggregate expression is not one of the supported binary comparators (<, <=, >, >=, ==, !=). It is a client-side input validation error in query parsing/evaluation.

Source

Thrown at query/aggregator.go:104

	isEqual, err := types.Equal(va, vb)
	if err != nil {
		return false, err
	}
	switch ag {
	case "<":
		return isLess, nil
	case ">":
		return isMore, nil
	case "<=":
		return isLess || isEqual, nil
	case ">=":
		return isMore || isEqual, nil
	case "==":
		return isEqual, nil
	case "!=":
		return !isEqual, nil
	}
	return false, errors.Errorf("Invalid compare function %q", ag)
}

func applyAdd(a, b, c *types.Val) error {
	vBase := getValType(a)
	switch vBase {
	case INT:
		aVal, bVal := a.Value.(int64), b.Value.(int64)
		if (aVal > 0 && bVal > math.MaxInt64-aVal) ||
			(aVal < 0 && bVal < math.MinInt64-aVal) {
			return ErrorIntOverflow
		}
		c.Value = aVal + bVal

	case FLOAT:
		c.Value = a.Value.(float64) + b.Value.(float64)
	case VFLOAT:
		// When adding vectors of floats, we add then item-wise
		// so that c.Value[i] = a.Value[i] + b.Value[i] for all i

View on GitHub (pinned to 759e242be6)

Solutions

  1. Use only supported operators: <, <=, >, >=, ==, !=
  2. Fix typos: replace '=' with '==' and '<>' with '!=' in DQL
  3. Validate query operator strings before sending in generated/programmatic queries

Example fix

// before
"filter": "age = 30"
// after
"filter": "age == 30"
Defensive patterns

Strategy: validation

Validate before calling

var validCompareOps = map[string]bool{"<":true,"<=":true,">":true,">=":true,"==":true,"!=":true}
func isValidCompareOp(op string) bool { return validCompareOps[op] }

Try / catch

ok, err := compareValues(ag, va, vb)
if err != nil && strings.HasPrefix(err.Error(), "Invalid compare function") {
    return fmt.Errorf("query used unsupported operator %q; use < <= > >= == !=", ag)
}

Prevention

When it happens

Trigger: A DQL query passes an unrecognized operator string into a comparison, e.g. math/uid filter expressions using an operator like "=", "<>", or a mistyped token that reaches compareValues without matching any case.

Common situations: Typos in queries ("=<" instead of "<="); generated queries from ORMs/tools emitting SQL-style operators; language localization or copy-paste of '=' or '<>' into DQL filters.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/cbf7a91eab2aa137. Report an issue: GitHub.