hasura/graphql-engine · error · AggregateBooleanExpressionError
the aggregation function '{aggregation_function_name}' retur
Error message
the aggregation function '{aggregation_function_name}' returns an array type ({aggregation_function_return_type}). Array types are not supported in aggregate comparisons What it means
Aggregate comparisons must compare against scalar values; this error is raised when the selected aggregation function's resolved return type is an array (e.g. array_agg or a connector-defined array-returning function). Comparing an array-typed result with scalar comparison operators is not supported, so resolution aborts.
Source
Thrown at v3/crates/metadata-resolve/src/stages/aggregate_boolean_expressions/types.rs:193
#[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(
"the {count_type} aggregation cannot be compared to because it is not enabled on the aggregate expression '{aggregate_expression}'"
)]
CountAggregateNotEnabled {
count_type: CountAggregateType,
aggregate_expression: Qualified<AggregateExpressionName>,
},
#[error(
"type mismatch between the '{count_type}' aggregate (return type: '{count_return_type}') and the specified boolean expression type '{boolean_expression_type}' (operand type: '{boolean_expression_operand_type}')"
)]View on GitHub (pinned to 724551b9ae)
Solutions
- Remove the array-returning aggregate from the comparison and use a scalar-returning aggregate instead
- If you need to filter on array contents, restructure the query/model to expose a scalar aggregate or filter at the row level
- Update connector metadata so the aggregate function returns a scalar type if the array return was unintentional
Example fix
// before
filter: { array_agg_field: { _eq: 1 } }
// after
filter: { count_field: { _eq: 1 } } // scalar-returning aggregate Defensive patterns
Strategy: validation
Validate before calling
if agg_fn.return_type.is_array() {
return Err("cannot compare array-returning aggregate; choose a scalar aggregate".into());
} Type guard
fn is_scalar_type(r: &QualifiedTypeReference) -> bool {
!matches!(r.underlying(), Type::Array(_))
} Try / catch
match resolve(expr) {
Err(ResolveError::ComparisonAgainstArrayTypesNotSupported { aggregation_function_name, .. }) => {
// fall back to a scalar aggregate or reject the query with a user-facing message
}
r => r,
} Prevention
- When adding custom aggregates, prefer scalar return types for comparable aggregates
- Reject array-returning aggregates in query builders before sending to metadata resolution
When it happens
Trigger: Using an aggregation function that returns an array type (like array_agg) inside a comparative aggregate / aggregate boolean expression where scalar comparisons (_eq, _gt, etc.) are expected.
Common situations: Adding array_agg or custom array-returning aggregate functions to connector capabilities and then attempting to filter on them; changing a custom aggregate function's return type from scalar to array in a new connector version while metadata still uses it in comparisons.
Related errors
- type mismatch between the aggregation function '{aggregation
- type mismatch between the '{count_type}' aggregate (return t
- could not find a scalar-operanded boolean expression type na
- the {count_type} aggregation cannot be compared to because i
- the operand type '{operand_type}' does not match the operand
AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28).
Data as JSON: /api/errors/7ced4d797f306f85.
Report an issue: GitHub.