dgraph-io/dgraph · error
Wrong type %v encountered for func ^
Error message
Wrong type %v encountered for func ^
What it means
applyPow returns this error when an exponentiation (^) operand has DEFAULT type. Power operations require numeric (int/float) typed values; DEFAULT indicates the operand is untyped or its payload is not numeric. Fractional powers of negative bases raise a separate ErrorFractionalPower.
Source
Thrown at query/aggregator.go:352
}
func applyPow(a, b, c *types.Val) error {
vBase := getValType(a)
switch vBase {
case INT:
c.Value = math.Pow(float64(a.Value.(int64)), float64(b.Value.(int64)))
c.Tid = types.FloatID
case FLOAT:
// Fractional power of -ve numbers should not be returned.
if a.Value.(float64) < 0 &&
math.Abs(math.Ceil(b.Value.(float64))-b.Value.(float64)) > 0 {
return ErrorFractionalPower
}
c.Value = math.Pow(a.Value.(float64), b.Value.(float64))
case DEFAULT:
return errors.Errorf("Wrong type %v encountered for func ^", a.Tid)
}
return nil
}
func applyLog(a, b, c *types.Val) error {
vBase := getValType(a)
switch vBase {
case INT:
if a.Value.(int64) < 0 || b.Value.(int64) < 0 {
return ErrorNegativeLog
} else if b.Value.(int64) == 1 {
return ErrorDivisionByZero
}
c.Value = math.Log(float64(a.Value.(int64))) / math.Log(float64(b.Value.(int64)))
c.Tid = types.FloatID
case FLOAT:
if a.Value.(float64) < 0 || b.Value.(float64) < 0 {View on GitHub (pinned to 759e242be6)
Solutions
- Give the predicate a numeric schema type (int/float)
- Validate both operands are numeric before the ^ expression
- Re-set or migrate values stored as the wrong type, then rebuild affected indexes
Example fix
// before math(score ^ 2) // score: DEFAULT // after // schema: score: float . math(score ^ 2)
Defensive patterns
Strategy: validation
Validate before calling
func isPowOperand(v types.Val) bool {
t := getValType(&v)
return t == INT || t == FLOAT
} Type guard
func canPow(a, b types.Val) bool {
return isPowOperand(a) && isPowOperand(b)
} Try / catch
if err := applyPow(a, b, c); err != nil {
switch {
case strings.Contains(err.Error(), "func ^"):
return fmt.Errorf("operand type %v not supported for ^; declare numeric schema type", a.Tid)
case errors.Is(err, ErrorFractionalPower):
return fmt.Errorf("negative base with fractional exponent")
}
return err
} Prevention
- Ensure exponentiated predicates are int/float typed
- Avoid ^ on uid or empty values
- Check sign/exponent combinations for fractional powers
- Validate computed score fields carry a schema type
When it happens
Trigger: math("^", a, b) evaluates where an operand's Tid is DEFAULT — e.g. squaring values of an untyped predicate or an empty/unconverted value reaching the math evaluator.
Common situations: Score computations (e.g. x^2) over predicates missing schema types; exponent variables bound to uid or empty values; data loaded without type conversion.
Related errors
- Wrong type %v encountered for func +
- Wrong type %v encountered for func -
- Wrong type %v encountered for func %%
- Wrong type %v encountered for func log
- Fail to convert from api.Value to types.Val
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/4999085a24efe031.
Report an issue: GitHub.