mikefarah/yq · error
arrays not yet supported for comparison
Error message
arrays not yet supported for comparison
What it means
Same limitation as the map case: yq's comparison operators (<, <=, >, >=) do not implement ordering for SequenceNode (array) operands. When the left-hand side of a comparison is an array, yq returns this error. Arrays are not naturally ordered in the comparator, so yq refuses rather than producing a bogus result.
Source
Thrown at pkg/yqlib/operator_compare.go:38
func compare(prefs compareTypePref) func(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) {
return func(_ *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) {
log.Debugf("compare cross function")
if lhs == nil && rhs == nil {
owner := &CandidateNode{}
return createBooleanCandidate(owner, prefs.OrEqual), nil
} else if lhs == nil {
log.Debugf("lhs nil, but rhs is not")
return createBooleanCandidate(rhs, false), nil
} else if rhs == nil {
log.Debugf("rhs nil, but rhs is not")
return createBooleanCandidate(lhs, false), nil
}
switch lhs.Kind {
case MappingNode:
return nil, fmt.Errorf("maps not yet supported for comparison")
case SequenceNode:
return nil, fmt.Errorf("arrays not yet supported for comparison")
default:
if rhs.Kind != ScalarNode {
return nil, fmt.Errorf("%v (%v) cannot be subtracted from %v", rhs.Tag, rhs.GetNicePath(), lhs.Tag)
}
target := lhs.CopyWithoutContent()
boolV, err := compareScalars(context, prefs, lhs, rhs)
return createBooleanCandidate(target, boolV), err
}
}
}
func compareDateTime(layout string, prefs compareTypePref, lhs *CandidateNode, rhs *CandidateNode) (bool, error) {
lhsTime, err := parseDateTime(layout, lhs.Value)
if err != nil {
return false, err
}
View on GitHub (pinned to 8b5af0694b)
Solutions
- Index into the array or compare its length: `(.items | length) > 3` instead of `.items > 3`.
- Sort by an inner key/element: `sort_by(.[0])` if ordering arrays is the goal.
- Use equality (== or contains) for array checks instead of ordering operators.
- Reshape the data so the operand is a scalar before comparing.
Example fix
# before yq '.servers > 2' file.yaml # servers is an array # after yq '(.servers | length) > 2' file.yaml
Defensive patterns
Strategy: type-guard
Validate before calling
# ensure the operand is not an array before comparing: yq -e '(.items | type) != "!!seq"' file.yaml || echo "operand is an array"
Type guard
// yq expression guard: only compare scalars // yq 'select(tag != "!!seq" and tag != "!!map") | . > 3' file.yaml
Prevention
- Use (expr | length) when you mean to compare sizes of arrays
- Index arrays (.items[0]) before ordering comparisons
- Use contains/any for membership checks instead of < or >
- Watch for schema drift turning scalars into lists
When it happens
Trigger: Any yq expression with <, <=, >, >= where the lhs evaluates to a sequence, e.g. `yq '.tags > ["a"]' file.yaml`, `yq '.items < 5'` where `.items` is an array, or min/max/sort_by over elements that are themselves arrays.
Common situations: Forgetting to index into an array (comparing `.ports` instead of `.ports[0]`); sorting an array of arrays; scripts where a field changed from a scalar to a list after a schema update; using length comparisons intended as `(.x | length) > 3` but written as `.x > 3`.
Related errors
- maps not yet supported for comparison
- %v not yet supported for comparison
- %v (%v) cannot be subtracted from %v
- %v not yet supported for contains
- can only pivot elements of !!seq or !!map types, received %v
AI-assisted analysis of mikefarah/yq@8b5af0694b (2026-09-05).
Data as JSON: /api/errors/ffa8289bd5c7c988.
Report an issue: GitHub.