{"record":{"id":"cbf7a91eab2aa137","repo":"dgraph-io/dgraph","slug":"invalid-compare-function-q","errorCode":null,"errorMessage":"Invalid compare function %q","messagePattern":"Invalid compare function %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/aggregator.go","lineNumber":104,"sourceCode":"\tisEqual, err := types.Equal(va, vb)\n\tif err != nil {\n\t\treturn false, err\n\t}\n\tswitch ag {\n\tcase \"<\":\n\t\treturn isLess, nil\n\tcase \">\":\n\t\treturn isMore, nil\n\tcase \"<=\":\n\t\treturn isLess || isEqual, nil\n\tcase \">=\":\n\t\treturn isMore || isEqual, nil\n\tcase \"==\":\n\t\treturn isEqual, nil\n\tcase \"!=\":\n\t\treturn !isEqual, nil\n\t}\n\treturn false, errors.Errorf(\"Invalid compare function %q\", ag)\n}\n\nfunc applyAdd(a, b, c *types.Val) error {\n\tvBase := getValType(a)\n\tswitch vBase {\n\tcase INT:\n\t\taVal, bVal := a.Value.(int64), b.Value.(int64)\n\t\tif (aVal > 0 && bVal > math.MaxInt64-aVal) ||\n\t\t\t(aVal < 0 && bVal < math.MinInt64-aVal) {\n\t\t\treturn ErrorIntOverflow\n\t\t}\n\t\tc.Value = aVal + bVal\n\n\tcase FLOAT:\n\t\tc.Value = a.Value.(float64) + b.Value.(float64)\n\tcase VFLOAT:\n\t\t// When adding vectors of floats, we add then item-wise\n\t\t// so that c.Value[i] = a.Value[i] + b.Value[i] for all i","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/query/aggregator.go#L86-L122","documentation":"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.","triggerScenarios":"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.","commonSituations":"Typos in queries (\"=<\" instead of \"<=\"); generated queries from ORMs/tools emitting SQL-style operators; language localization or copy-paste of '=' or '<>' into DQL filters.","solutions":["Use only supported operators: <, <=, >, >=, ==, !=","Fix typos: replace '=' with '==' and '<>' with '!=' in DQL","Validate query operator strings before sending in generated/programmatic queries"],"exampleFix":"// before\n\"filter\": \"age = 30\"\n// after\n\"filter\": \"age == 30\"","handlingStrategy":"validation","validationCode":"var validCompareOps = map[string]bool{\"<\":true,\"<=\":true,\">\":true,\">=\":true,\"==\":true,\"!=\":true}\nfunc isValidCompareOp(op string) bool { return validCompareOps[op] }","typeGuard":null,"tryCatchPattern":"ok, err := compareValues(ag, va, vb)\nif err != nil && strings.HasPrefix(err.Error(), \"Invalid compare function\") {\n    return fmt.Errorf(\"query used unsupported operator %q; use < <= > >= == !=\", ag)\n}","preventionTips":["Only use <, <=, >, >=, ==, != in DQL comparisons","Translate SQL operators ('=', '<>') before sending DQL","Validate operator strings in query builders/generators","Lint queries for common typos like '=<', '=>'"],"tags":["query","dql","validation"],"backgroundTag":"invalid-operator","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}