dgraph-io/dgraph · error
Value variables not supported for predicate with list type.
Error message
Value variables not supported for predicate with list type.
What it means
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.
Source
Thrown at query/query.go:1640
}
// For a recurse query this can happen. We don't allow using the same variable more than
// once otherwise.
lists := append([]*pb.List(nil), v.Uids, uids)
v.Uids = algo.MergeSorted(lists)
doneVars[sg.Params.Var] = v
case len(sg.valueMatrix) != 0 && sg.SrcUIDs != nil && len(sgPath) != 0:
// 4. A value variable. We get the first value from every list thats part of ValueMatrix
// and store it corresponding to a uid in SrcUIDs.
if v, ok = doneVars[sg.Params.Var]; !ok {
v.Vals = types.NewShardedMap()
v.path = sgPath
v.strList = sg.valueMatrix
}
for idx, uid := range sg.SrcUIDs.Uids {
if len(sg.valueMatrix[idx].Values) > 1 {
return errors.Errorf("Value variables not supported for predicate with list type.")
}
if len(sg.valueMatrix[idx].Values) == 0 {
continue
}
val, err := convertWithBestEffort(sg.valueMatrix[idx].Values[0], sg.Attr)
if err != nil {
continue
}
v.Vals.Set(uid, val)
}
doneVars[sg.Params.Var] = v
default:
// If the variable already existed and now we see it again without any DestUIDs or
// ValueMatrix then lets just return.
if _, ok := doneVars[sg.Params.Var]; ok {
return nil
}View on GitHub (pinned to 759e242be6)
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
Example fix
// before: tags is [string]
{
me(func: uid(1)) { t as tags }
other(func: uid(2)) { uses(val(t)) }
}
// after: use a scalar predicate
{
me(func: uid(1)) { t as primary_tag }
other(func: uid(2)) { uses(val(t)) }
} Defensive patterns
Strategy: validation
Validate before calling
// Before capturing a predicate into a value variable, confirm it is not a list type
if schemaType(pred) == "list" {
return fmt.Errorf("cannot use value variable on list-type predicate %s", pred)
} Type guard
func isScalarPredicate(t string) bool { return t == "string" || t == "int" || t == "float" || t == "bool" || t == "datetime" || t == "uid" } Try / catch
if err != nil && strings.Contains(err.Error(), "Value variables not supported for predicate with list type") {
return fmt.Errorf("predicate is a list type; use len() or aggregation instead: %w", err)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Wrong type %v encountered for func ln
- Wrong type %v encountered for func exp
- Wrong type %v encountered for func u-
- Wrong type %v encountered for func sqrt
- Wrong type %v encountered for func floor
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/01e05c6c8caa090f.
Report an issue: GitHub.