hasura/graphql-engine · error · AggregateBooleanExpressionError

type mismatch between the aggregation function '{aggregation

Error message

type mismatch between the aggregation function '{aggregation_function_name}' (return type: '{aggregation_function_return_type}') and the specified boolean expression type '{boolean_expression_type}' (operand type: '{boolean_expression_operand_type}')

What it means

During resolution of an aggregate boolean expression, the aggregation function's return type must match the operand type of the chosen boolean expression type. This error is thrown when comparing an aggregation function (e.g. avg, sum, min, max) whose return type differs from the scalar type the boolean expression type operates on, making the comparison ill-typed.

Source

Thrown at v3/crates/metadata-resolve/src/stages/aggregate_boolean_expressions/types.rs:183

        aggregation_function_name: AggregationFunctionName,
    },

    #[error(
        "the aggregation function '{aggregation_function_name}' is not defined in the aggregate expression '{aggregate_expression}'"
    )]
    AggregationFunctionNotFound {
        aggregation_function_name: AggregationFunctionName,
        aggregate_expression: Qualified<AggregateExpressionName>,
    },

    #[error(
        "could not find a scalar-operanded boolean expression type named '{boolean_expression_type}'"
    )]
    ScalarBooleanExpressionTypeNotFound {
        boolean_expression_type: BooleanExpressionTypeIdentifier,
    },

    #[error(
        "type mismatch between the aggregation function '{aggregation_function_name}' (return type: '{aggregation_function_return_type}') and the specified boolean expression type '{boolean_expression_type}' (operand type: '{boolean_expression_operand_type}')"
    )]
    AggregationFunctionTypeMismatch {
        aggregation_function_name: AggregationFunctionName,
        aggregation_function_return_type: QualifiedTypeName,
        boolean_expression_type: BooleanExpressionTypeIdentifier,
        boolean_expression_operand_type: QualifiedTypeName,
    },

    #[error(
        "the aggregation function '{aggregation_function_name}' returns an array type ({aggregation_function_return_type}). Array types are not supported in aggregate comparisons"
    )]
    ComparisonAgainstArrayTypesNotSupported {
        aggregation_function_name: AggregationFunctionName,
        aggregation_function_return_type: QualifiedTypeReference,
    },

    #[error(

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Check the aggregation function's return type in the connector's capability/schema and pick a boolean expression type whose operand type matches it exactly
  2. If the scalar types should be equivalent, fix the underlying scalar type mapping in metadata so the qualified names match
  3. Update the boolean expression type used in the aggregate comparison to one defined on the aggregate's return type

Example fix

// before
aggregate: { avg: { field: price } }
filter: { avg: { _eq: $val } } // _eq operand Int but avg returns Float

// after
aggregate: { avg: { field: price } }
filter: { avg: { _eq: $val } } // use Float-typed comparison / matching bool exp type
Defensive patterns

Strategy: validation

Validate before calling

// check aggregate return type matches bool exp operand type before building filter
assert_eq!(agg_fn.return_type.qualified_name(), bool_exp.operand_type.qualified_name(),
    "aggregate/boolean-expression operand type mismatch");

Type guard

fn types_compatible(agg_ret: &QualifiedTypeName, operand: &QualifiedTypeName) -> bool {
    agg_ret == operand
}

Try / catch

match resolve(expr) {
    Err(ResolveError::AggregationFunctionTypeMismatch { aggregation_function_name, .. }) => {
        // pick a bool exp type matching the aggregate's return type and retry once
    }
    r => r,
}

Prevention

When it happens

Trigger: Comparing an aggregate like avg (returns Float/numeric) against a boolean expression type whose operand is e.g. String or Int; specifying filter expressions that use a boolean_expression_type built for a different scalar type than the aggregate's output type.

Common situations: Switching an aggregation function in metadata (e.g. from count to avg) without updating the boolean expression type used in the comparison; boolean expression types auto-generated per-type being mixed up when hand-writing comparative aggregate filters; connector returning a different scalar type after a version upgrade.

Related errors


AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28). Data as JSON: /api/errors/dde4241992616372. Report an issue: GitHub.