{"record":{"id":"01e05c6c8caa090f","repo":"dgraph-io/dgraph","slug":"value-variables-not-supported-for-predicate-with-l","errorCode":null,"errorMessage":"Value variables not supported for predicate with list type.","messagePattern":"Value variables not supported for predicate with list type\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/query.go","lineNumber":1640,"sourceCode":"\t\t}\n\n\t\t// For a recurse query this can happen. We don't allow using the same variable more than\n\t\t// once otherwise.\n\t\tlists := append([]*pb.List(nil), v.Uids, uids)\n\t\tv.Uids = algo.MergeSorted(lists)\n\t\tdoneVars[sg.Params.Var] = v\n\tcase len(sg.valueMatrix) != 0 && sg.SrcUIDs != nil && len(sgPath) != 0:\n\t\t// 4. A value variable. We get the first value from every list thats part of ValueMatrix\n\t\t// and store it corresponding to a uid in SrcUIDs.\n\t\tif v, ok = doneVars[sg.Params.Var]; !ok {\n\t\t\tv.Vals = types.NewShardedMap()\n\t\t\tv.path = sgPath\n\t\t\tv.strList = sg.valueMatrix\n\t\t}\n\n\t\tfor idx, uid := range sg.SrcUIDs.Uids {\n\t\t\tif len(sg.valueMatrix[idx].Values) > 1 {\n\t\t\t\treturn errors.Errorf(\"Value variables not supported for predicate with list type.\")\n\t\t\t}\n\n\t\t\tif len(sg.valueMatrix[idx].Values) == 0 {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tval, err := convertWithBestEffort(sg.valueMatrix[idx].Values[0], sg.Attr)\n\t\t\tif err != nil {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tv.Vals.Set(uid, val)\n\t\t}\n\t\tdoneVars[sg.Params.Var] = v\n\tdefault:\n\t\t// If the variable already existed and now we see it again without any DestUIDs or\n\t\t// ValueMatrix then lets just return.\n\t\tif _, ok := doneVars[sg.Params.Var]; ok {\n\t\t\treturn nil\n\t\t}","sourceCodeStart":1622,"sourceCodeEnd":1658,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/query/query.go#L1622-L1658","documentation":"Value variables (val(x)) capture a single value per source UID. When the predicate has a list type, a node can hold multiple values, so Dgraph refuses to materialize a value variable over it and throws this error when it detects more than one value in a valueMatrix cell.","triggerScenarios":"Using 'as var' / val() on a predicate whose schema type is [type] (a list), and a node has 2+ values for that predicate; e.g. 'friend { tags as tags }' where tags is a list.","commonSituations":"Schema defines the predicate as a list but the query treats it as scalar for variable capture; data written to a predicate later migrated to list type; queries copied from scalar predicates to list predicates.","solutions":["Check the schema (/state) — if the predicate is a list type, do not capture it into a value variable","Change the predicate schema to scalar if single-valued semantics are intended (requires data migration)","Use math/aggregation over the list via supported functions (e.g. len()) instead of value vars","Use @groupby or an aggregation without value-variable capture"],"exampleFix":"// before: tags is [string]\n{\n  me(func: uid(1)) { t as tags }\n  other(func: uid(2)) { uses(val(t)) }\n}\n// after: use a scalar predicate\n{\n  me(func: uid(1)) { t as primary_tag }\n  other(func: uid(2)) { uses(val(t)) }\n}","handlingStrategy":"validation","validationCode":"// Before capturing a predicate into a value variable, confirm it is not a list type\nif schemaType(pred) == \"list\" {\n    return fmt.Errorf(\"cannot use value variable on list-type predicate %s\", pred)\n}","typeGuard":"func isScalarPredicate(t string) bool { return t == \"string\" || t == \"int\" || t == \"float\" || t == \"bool\" || t == \"datetime\" || t == \"uid\" }","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"Value variables not supported for predicate with list type\") {\n    return fmt.Errorf(\"predicate is a list type; use len() or aggregation instead: %w\", err)\n}","preventionTips":["Check /state or schema JSON before writing value-variable queries","Keep list and scalar predicates under distinct, clearly named predicates","Document which predicates are lists and forbid val() capture in query templates"],"tags":["dgraph","query","value-variables","list-type"],"backgroundTag":"value-variable-on-list-predicate","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}