{"record":{"id":"e983c42017852d1e","repo":"mikefarah/yq","slug":"maps-not-yet-supported-for-subtraction","errorCode":null,"errorMessage":"maps not yet supported for subtraction","messagePattern":"maps not yet supported for subtraction","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_subtract.go","lineNumber":52,"sourceCode":"\t\t\t}\n\t\t}\n\t\tif shouldInclude {\n\t\t\tnewLHSArray = append(newLHSArray, lhs.Content[lindex])\n\t\t}\n\t}\n\treturn newLHSArray\n}\n\nfunc subtract(_ *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) {\n\tif lhs.Tag == \"!!null\" {\n\t\treturn lhs.CopyAsReplacement(rhs), nil\n\t}\n\n\ttarget := lhs.CopyWithoutContent()\n\n\tswitch lhs.Kind {\n\tcase MappingNode:\n\t\treturn nil, fmt.Errorf(\"maps not yet supported for subtraction\")\n\tcase SequenceNode:\n\t\tif rhs.Kind != SequenceNode {\n\t\t\treturn nil, fmt.Errorf(\"%v (%v) cannot be subtracted from %v\", rhs.Tag, rhs.GetNicePath(), lhs.Tag)\n\t\t}\n\t\ttarget.Content = subtractArray(lhs, rhs)\n\tcase ScalarNode:\n\t\tif rhs.Kind != ScalarNode {\n\t\t\treturn nil, fmt.Errorf(\"%v (%v) cannot be subtracted from %v\", rhs.Tag, rhs.GetNicePath(), lhs.Tag)\n\t\t}\n\t\ttarget.Kind = ScalarNode\n\t\ttarget.Style = lhs.Style\n\t\tif err := subtractScalars(context, target, lhs, rhs); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\n\treturn target, nil\n}","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_subtract.go#L34-L70","documentation":"The subtract operator in operator_subtract.go supports arrays (set difference), scalars (numbers, and string/element removal variants), but not mappings. Subtracting anything from a map node immediately returns 'maps not yet supported for subtraction' — this is an explicit unimplemented-feature guard, not a data error.","triggerScenarios":"Expressions like '.myMap - {a: 1}', '.config - [\"key1\"]' where .config is a mapping, or '.obj - .other' when either operand evaluates to a MappingNode. Also hit via arithmetic paths like '(.a + 1) - .map'.","commonSituations":"Users coming from jq expecting object subtraction/key removal; trying to delete keys from a map with '-' instead of 'del()'; Kubernetes config patching attempts that subtract whole objects.","solutions":["Use 'del()' to remove keys from a map: 'del(.obj.key1, .obj.key2)' or 'del(.obj[] | select(...))' style paths.","To remove a set of keys dynamically: 'del(.obj.[(.keys | .[])])' or '.obj | del(.[] | select(.key in $keys))' variants depending on the desired semantics.","If set-difference was intended, ensure both operands are arrays/sequences: '[.list1[]] - [.list2[]]'."],"exampleFix":"// before (fails: maps unsupported)\nyq '.env - {DEBUG: true}' config.yaml\n\n// after: remove specific keys\nyq 'del(.env.DEBUG)' config.yaml","handlingStrategy":"validation","validationCode":"KIND=$(yq '.a | kind' file.yaml); [ \"$KIND\" != \"map\" ] || { echo \"subtraction not supported for maps; use del()\"; exit 1; }","typeGuard":"// in yq: select(kind != \"map\") | . - other\nfunction isMapNode(node) { return node && node.kind === 'map'; }","tryCatchPattern":"out=$(yq '.env - {DEBUG: true}' file.yaml 2>&1) || { echo \"map subtraction unsupported: $out\"; out=\"$(yq 'del(.env.DEBUG)' file.yaml)\"; }","preventionTips":["Never use '-' on mappings; use del(path) for key removal.","Use array set-difference form '[.a[]] - [.b[]]' when deduplication/difference is intended.","Check operand kinds with 'kind' when building arithmetic expressions over mixed documents."],"tags":["yq","arithmetic","unsupported-operation","maps"],"backgroundTag":"operation-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"}