hasura/graphql-engine · error · Error
Aggregate function ${f} is not supported by SQLite. See: htt
Error message
Aggregate function ${f} is not supported by SQLite. See: https://www.sqlite.org/lang_aggfunc.html What it means
cast_aggregate_function whitelists SQLite's supported aggregate functions (avg, count, group_concat, max, min, sum, total). Any other aggregate name in a query's aggregate list throws with a link to SQLite's aggregate function docs, because the agent will not emit SQL for aggregates SQLite cannot execute.
Source
Thrown at dc-agents/sqlite/src/query.ts:431
}
}
break;
}
throw new Error(
`Couldn't find table relationships for target ${JSON.stringify(target)} - This shouldn't happen.`,
);
}
function cast_aggregate_function(f: string): string {
switch (f) {
case 'avg':
case 'max':
case 'min':
case 'sum':
case 'total':
return f;
default:
throw new Error(
`Aggregate function ${f} is not supported by SQLite. See: https://www.sqlite.org/lang_aggfunc.html`,
);
}
}
/**
* Builds an Aggregate query expression.
*/
function aggregates_query(
allRelationships: Relationships[],
target: Target,
joinInfo: RelationshipJoinInfo | null,
aggregates: Aggregates,
wWhere: Expression | null,
wLimit: number | null,
wOffset: number | null,
wOrder: OrderBy | null,
): string {View on GitHub (pinned to 724551b9ae)
Solutions
- Restrict aggregates to avg, count, group_concat, max, min, sum, total
- Compute unsupported aggregates in an interpolated target (e.g. a SQL CTE you control) or client-side
- Register a custom SQLite aggregate function only if you also extend the agent's whitelist
Example fix
// before
aggregates: { pops: { function: 'stddev', column: 'population' } }
// after
aggregates: { pops: { function: 'avg', column: 'population' } } Defensive patterns
Strategy: validation
Validate before calling
const SQLITE_AGGS = new Set(['avg','count','group_concat','max','min','sum','total']);
for (const a of Object.values(aggregates)) if (!SQLITE_AGGS.has(a.function)) throw new Error(`Unsupported aggregate ${a.function}`); Type guard
const isSqliteAggregate = (f: string): f is 'avg'|'count'|'group_concat'|'max'|'min'|'sum'|'total' => SQLITE_AGGS.has(f);
Prevention
- Keep an allowlist of SQLite aggregates in client code
- Don't port statistical aggregates from other engines; compute client-side
When it happens
Trigger: Requesting an aggregate like `stddev`, `variance`, `median`, `array_agg`, or any vendor-specific aggregate (Postgres/BigQuery style) in the aggregates section of a query.
Common situations: Reusing queries written for another database engine against the SQLite agent; dashboards requesting statistical aggregates SQLite lacks; metadata declaring aggregates not in SQLite's function set.
Related errors
- ${tableName.join('.')} is not a valid table
- `escapeTargetName` only implemented for tables and interpola
- Couldn't find relationship ${field.relationship} for field $
- Unsupported field type "object"
- Unsupported field type "array"
AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28).
Data as JSON: /api/errors/f865a62f268ce8b9.
Report an issue: GitHub.