dgraph-io/dgraph · error

uid count is not supported in the rdf output format

Error message

uid count is not supported in the rdf output format

What it means

Counting the internal uid node (`count(uid)` on the uid attribute) is rejected during RDF serialization. validateSubGraphForRDF detects sg.Attr == "uid" with DoCount on an internal sub-graph and refuses it because a UID count has no meaningful RDF representation.

Source

Thrown at query/outputrdf.go:220

		buf = append(buf, '<')
		buf = append(buf, val...)
		buf = append(buf, '>')
		return buf
	}
	buf := make([]byte, 0, overhead+len(val))
	buf = append(buf, '<')
	buf = append(buf, val...)
	buf = append(buf, '>')
	return buf
}

func validateSubGraphForRDF(sg *SubGraph) error {
	if sg.IsGroupBy() {
		return errors.New("groupby is not supported in rdf output format")
	}
	uidCount := sg.Attr == "uid" && sg.Params.DoCount && sg.IsInternal()
	if uidCount {
		return errors.New("uid count is not supported in the rdf output format")
	}
	if sg.Params.Normalize {
		return errors.New("normalize directive is not supported in the rdf output format")
	}
	if sg.Params.IgnoreReflex {
		return errors.New("ignorereflex directive is not supported in the rdf output format")
	}
	if sg.SrcFunc != nil && sg.SrcFunc.Name == "checkpwd" {
		return errors.New("chkpwd function is not supported in the rdf output format")
	}
	if sg.Params.Facet != nil && !sg.Params.ExpandAll {
		return errors.New("facets are not supported in the rdf output format")
	}
	return nil
}

func quotedNumber(val []byte) []byte {
	const overhead = 2 // opening and closing quotes

View on GitHub (pinned to 759e242be6)

Solutions

  1. Request JSON output for queries containing count(uid)
  2. Move the count into a separate JSON-format query
  3. Count results client-side from the expanded RDF/JSON data

Example fix

// before (rdf output)
{ q(func: type(Person)) { count(uid) } }
// after
// run with JSON output, or: { q(func: type(Person)) { uid name } } and count client-side
Defensive patterns

Strategy: validation

Validate before calling

// Go: reject internal count(uid) before RDF output
if strings.Contains(query, "count(uid)") {
    return errors.New("count(uid) requires JSON output")
}

Type guard

func hasUidCount(dql string) bool {
    return strings.Contains(strings.ToLower(dql), "count(uid)")
}

Try / catch

res, err := txn.QueryRDF(ctx, dql)
if err != nil && strings.Contains(err.Error(), "uid count is not supported") {
    return txn.Query(ctx, dql) // JSON fallback
}

Prevention

When it happens

Trigger: A query containing an internal `count(uid)` aggregation (e.g. `{ q(func: type(Person)) { count(uid) } }`) executed with RDF output format.

Common situations: Exporting aggregate counts alongside node data in RDF; dashboards configured to always emit RDF.

Related errors


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