hasura/graphql-engine · error

the aggregation function {field_name} conflicts with the agg

Error message

the aggregation function {field_name} conflicts with the aggregatable field {field_name} in the aggregate expression {aggregate_expression} is named {field_name}. Either rename the aggregation function or the field

What it means

Schema-build error for aggregate expressions: when generating aggregate fields, the aggregation function's field name (e.g. `count`, `sum`) collides with the name of an aggregatable field inside the aggregate expression. The message names the conflicting field and the aggregate expression to fix.

Source

Thrown at v3/crates/graphql/schema/src/lib.rs:334

    )]
    InternalCommandArgumentPresetLookupFailure {
        command_name: Qualified<CommandName>,
        role: Role,
    },
    #[error("duplicate field name {field_name} generated while building object type {type_name}")]
    DuplicateFieldNameGeneratedInObjectType {
        field_name: ast::Name,
        type_name: Qualified<CustomTypeName>,
    },
    #[error(
        "field name for relationship {relationship_name} of type {type_name} conflicts with the existing field {field_name}"
    )]
    RelationshipFieldNameConflict {
        relationship_name: RelationshipName,
        field_name: ast::Name,
        type_name: Qualified<CustomTypeName>,
    },
    #[error(
        "the aggregation function {field_name} conflicts with the aggregatable field {field_name} in the aggregate expression {aggregate_expression} is named {field_name}. Either rename the aggregation function or the field"
    )]
    AggregationFunctionFieldNameConflict {
        aggregate_expression: Qualified<AggregateExpressionName>,
        field_name: ast::Name,
    },
    #[error(
        "internal error: duplicate aggregatable field {field_name} in the aggregate expression {aggregate_expression} is named {field_name}"
    )]
    InternalDuplicateAggregatableField {
        aggregate_expression: Qualified<AggregateExpressionName>,
        field_name: ast::Name,
    },
    #[error(
        "internal error: duplicate models with global id implementing the same type {type_name} are found"
    )]
    InternalErrorDuplicateGlobalIdSourceFound { type_name: ast::TypeName },
    #[error(

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Rename the aggregatable field (or its GraphQL name mapping) in the aggregate expression
  2. Or rename/override the aggregation function field name if the metadata allows it
  3. Avoid naming columns after aggregation function names when designing the schema

Example fix

# before: column named "count" is aggregated
aggregate { count { count } }
# after: rename the column's field mapping
aggregate { count { total_count } }
Defensive patterns

Strategy: validation

Validate before calling

// Guard aggregation field names against function names
const FN_NAMES: [&str; 5] = ["count", "sum", "avg", "min", "max"];
assert!(!FN_NAMES.contains(&field.graphql_name()), "field {} collides with aggregation function", field.graphql_name());

Try / catch

// Catch Error::AggregationFunctionFieldNameConflict { aggregate_expression, field_name } and rename the aggregatable field

Prevention

When it happens

Trigger: An aggregate expression selects a field whose name equals a generated aggregation function field — e.g. aggregating a column literally named `count` or `avg` so that `count { count }` would be generated.

Common situations: Database columns named count/sum/avg/min/max used in aggregations, aggregate expressions built programmatically without checking reserved function names.

Related errors


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