{"record":{"id":"92b5ad7106210587","repo":"mikefarah/yq","slug":"maps-not-yet-supported-for-comparison","errorCode":null,"errorMessage":"maps not yet supported for comparison","messagePattern":"maps not yet supported for comparison","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_compare.go","lineNumber":36,"sourceCode":"}\n\nfunc compare(prefs compareTypePref) func(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) {\n\treturn func(_ *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) {\n\t\tlog.Debugf(\"compare cross function\")\n\t\tif lhs == nil && rhs == nil {\n\t\t\towner := &CandidateNode{}\n\t\t\treturn createBooleanCandidate(owner, prefs.OrEqual), nil\n\t\t} else if lhs == nil {\n\t\t\tlog.Debugf(\"lhs nil, but rhs is not\")\n\t\t\treturn createBooleanCandidate(rhs, false), nil\n\t\t} else if rhs == nil {\n\t\t\tlog.Debugf(\"rhs nil, but rhs is not\")\n\t\t\treturn createBooleanCandidate(lhs, false), nil\n\t\t}\n\n\t\tswitch lhs.Kind {\n\t\tcase MappingNode:\n\t\t\treturn nil, fmt.Errorf(\"maps not yet supported for comparison\")\n\t\tcase SequenceNode:\n\t\t\treturn nil, fmt.Errorf(\"arrays not yet supported for comparison\")\n\t\tdefault:\n\t\t\tif rhs.Kind != ScalarNode {\n\t\t\t\treturn nil, fmt.Errorf(\"%v (%v) cannot be subtracted from %v\", rhs.Tag, rhs.GetNicePath(), lhs.Tag)\n\t\t\t}\n\t\t\ttarget := lhs.CopyWithoutContent()\n\t\t\tboolV, err := compareScalars(context, prefs, lhs, rhs)\n\n\t\t\treturn createBooleanCandidate(target, boolV), err\n\t\t}\n\t}\n}\n\nfunc compareDateTime(layout string, prefs compareTypePref, lhs *CandidateNode, rhs *CandidateNode) (bool, error) {\n\tlhsTime, err := parseDateTime(layout, lhs.Value)\n\tif err != nil {\n\t\treturn false, err","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_compare.go#L18-L54","documentation":"The comparison operators (<, <=, >, >= in yq) only support scalar operands. When the LEFT-hand side of a comparison is a map (MappingNode), yq has no defined ordering for maps and returns this error instead of guessing. It is a deliberate 'not yet supported' limitation of the comparator implementation.","triggerScenarios":"Any yq expression using <, <=, >, or >= where the lhs evaluates to a mapping node, e.g. `yq '.config > 3' file.yaml` where `.config` is a map, or `sort_by`/`min`/`max` over a sequence of maps where the comparator receives a whole map as the lhs.","commonSituations":"Pointing a comparison at the wrong key (comparing a nested object instead of the scalar inside it); calling sort_by(...) with a path that resolves to a map; using min/max over documents that are maps rather than scalar arrays; schema drift where a field that used to be a number became a nested object.","solutions":["Navigate to the scalar inside the map before comparing, e.g. `.config.size > 3` instead of `.config > 3`.","If you must order maps, sort by a specific key: `sort_by(.name)` rather than comparing whole maps.","Use equality (==) which supports maps, if ordering is not actually needed.","Split the comparison: extract the scalar with a separate expression, then compare."],"exampleFix":"# before\nyq '.metadata > 2' file.yaml   # metadata is a map\n# after\nyq '.metadata.replicas > 2' file.yaml","handlingStrategy":"type-guard","validationCode":"# ensure the lhs is a scalar before comparing:\nyq -e '.config | type == \"!!scalar\"' file.yaml || echo \"lhs is not a scalar\"","typeGuard":"// yq expression guard: select only scalar lhs before comparing\n// yq '.[] | select(tag == \"!!int\" or tag == \"!!float\" or tag == \"!!str\") | . > 3' file.yaml","tryCatchPattern":null,"preventionTips":["Always drill to a leaf scalar field before using <, <=, >, >=","Use `tag` or `type` to sanity-check operands during development","Prefer sort_by(key) over comparing whole maps","Remember only == supports maps; use it when ordering is not needed"],"tags":["yq","comparison-operator","unsupported-type","map"],"backgroundTag":"comparison-not-supported-for-type","analyzedSha":"8b5af0694bb82b41d4ae180fac9972029066f90a","analyzedAt":"2026-09-05T10:57:22.766Z","contentChangedAt":"2026-09-05T10:57:22.766Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}