{"record":{"id":"0396ae8af02f8ee0","repo":"dgraph-io/dgraph","slug":"uid-count-is-not-supported-in-the-rdf-output-forma","errorCode":null,"errorMessage":"uid count is not supported in the rdf output format","messagePattern":"uid count is not supported in the rdf output format","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/outputrdf.go","lineNumber":220,"sourceCode":"\t\tbuf = append(buf, '<')\n\t\tbuf = append(buf, val...)\n\t\tbuf = append(buf, '>')\n\t\treturn buf\n\t}\n\tbuf := make([]byte, 0, overhead+len(val))\n\tbuf = append(buf, '<')\n\tbuf = append(buf, val...)\n\tbuf = append(buf, '>')\n\treturn buf\n}\n\nfunc validateSubGraphForRDF(sg *SubGraph) error {\n\tif sg.IsGroupBy() {\n\t\treturn errors.New(\"groupby is not supported in rdf output format\")\n\t}\n\tuidCount := sg.Attr == \"uid\" && sg.Params.DoCount && sg.IsInternal()\n\tif uidCount {\n\t\treturn errors.New(\"uid count is not supported in the rdf output format\")\n\t}\n\tif sg.Params.Normalize {\n\t\treturn errors.New(\"normalize directive is not supported in the rdf output format\")\n\t}\n\tif sg.Params.IgnoreReflex {\n\t\treturn errors.New(\"ignorereflex directive is not supported in the rdf output format\")\n\t}\n\tif sg.SrcFunc != nil && sg.SrcFunc.Name == \"checkpwd\" {\n\t\treturn errors.New(\"chkpwd function is not supported in the rdf output format\")\n\t}\n\tif sg.Params.Facet != nil && !sg.Params.ExpandAll {\n\t\treturn errors.New(\"facets are not supported in the rdf output format\")\n\t}\n\treturn nil\n}\n\nfunc quotedNumber(val []byte) []byte {\n\tconst overhead = 2 // opening and closing quotes","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/query/outputrdf.go#L202-L238","documentation":"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.","triggerScenarios":"A query containing an internal `count(uid)` aggregation (e.g. `{ q(func: type(Person)) { count(uid) } }`) executed with RDF output format.","commonSituations":"Exporting aggregate counts alongside node data in RDF; dashboards configured to always emit RDF.","solutions":["Request JSON output for queries containing count(uid)","Move the count into a separate JSON-format query","Count results client-side from the expanded RDF/JSON data"],"exampleFix":"// before (rdf output)\n{ q(func: type(Person)) { count(uid) } }\n// after\n// run with JSON output, or: { q(func: type(Person)) { uid name } } and count client-side","handlingStrategy":"validation","validationCode":"// Go: reject internal count(uid) before RDF output\nif strings.Contains(query, \"count(uid)\") {\n    return errors.New(\"count(uid) requires JSON output\")\n}","typeGuard":"func hasUidCount(dql string) bool {\n    return strings.Contains(strings.ToLower(dql), \"count(uid)\")\n}","tryCatchPattern":"res, err := txn.QueryRDF(ctx, dql)\nif err != nil && strings.Contains(err.Error(), \"uid count is not supported\") {\n    return txn.Query(ctx, dql) // JSON fallback\n}","preventionTips":["Run aggregate counts in separate JSON queries","Do not mix aggregation and RDF export in one query","Detect count(uid) patterns in query templates"],"tags":["dgraph","rdf","count","query-validation"],"backgroundTag":"feature-not-supported-in-rdf-output","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}