dgraph-io/dgraph · error

Wrong type %v encountered for func -

Error message

Wrong type %v encountered for func -

What it means

applySub returns this error when a subtraction (-) operand has DEFAULT type, meaning the value is untyped or unsupported for arithmetic. Subtraction requires int/float/bigfloat typed values; DEFAULT signals missing type metadata on the operand.

Source

Thrown at query/aggregator.go:188

		if !ok {
			return ErrorArgsDisagree
		}
		if len(aVal) != len(bVal) {
			return ErrorVectorsNotMatch
		}
		cVal := make([]float32, len(aVal))
		for i := range aVal {
			cVal[i] = aVal[i] - bVal[i]
		}
		c.Value = cVal

	case BIGFLOAT:
		aVal, bVal := a.Value.(big.Float), b.Value.(big.Float)
		aVal.Sub(&aVal, &bVal)
		c.Value = aVal

	case DEFAULT:
		return errors.Errorf("Wrong type %v encountered for func -", a.Tid)
	}
	return nil
}

func applyMul(a, b, c *types.Val) error {
	// Possible input combinations:
	//   INT * INT
	//   FLOAT * FLOAT
	//   FLOAT * VFLOAT
	//   VFLOAT * FLOAT
	// Other combinations should have been eliminated via matchType.
	// Some operations, such as INT * FLOAT might be allowed conceptually,
	// but we would have already cast the INT value to a FLOAT in the
	// matchType invocation.
	lValType := getValType(a)
	rValType := getValType(b)
	switch lValType {
	case INT:

View on GitHub (pinned to 759e242be6)

Solutions

  1. Add a concrete scalar type to the predicate's schema before doing math
  2. Validate operands are numeric before the subtraction expression
  3. Handle empty/missing values with filters or conditional logic in the query

Example fix

// before
math(a - b) // b: DEFAULT type
// after
// schema: b: float .
math(a - b) // now valid once b is stored as float
Defensive patterns

Strategy: validation

Validate before calling

func isSubtractable(a, b types.Val) bool {
    t := getValType(a)
    return t == INT || t == FLOAT || t == BIGFLOAT
}

Type guard

func hasNumericTid(v types.Val) bool {
    t := getValType(&v)
    return t != DEFAULT && (t == INT || t == FLOAT || t == BIGFLOAT)
}

Try / catch

if err := applySub(a, b, c); err != nil {
    if strings.Contains(err.Error(), "func -") {
        return fmt.Errorf("operand type %v not supported for -; ensure values are typed numerics", a.Tid)
    }
    return err
}

Prevention

When it happens

Trigger: math("-", a, b) evaluates where an operand's Tid is DEFAULT — typically an untyped predicate value, an empty value, or a value that failed upstream type conversion.

Common situations: Subtracting values from predicates lacking a schema type; date/time arithmetic attempted with untyped values; queries over partially loaded or empty data.

Related errors


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