{"record":{"id":"f865a62f268ce8b9","repo":"hasura/graphql-engine","slug":"aggregate-function-f-is-not-supported-by-sqlite","errorCode":null,"errorMessage":"Aggregate function ${f} is not supported by SQLite. See: https://www.sqlite.org/lang_aggfunc.html","messagePattern":"Aggregate function (.+?) is not supported by SQLite\\. See: https://www\\.sqlite\\.org/lang_aggfunc\\.html","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"dc-agents/sqlite/src/query.ts","lineNumber":431,"sourceCode":"        }\n      }\n      break;\n  }\n  throw new Error(\n    `Couldn't find table relationships for target ${JSON.stringify(target)} - This shouldn't happen.`,\n  );\n}\n\nfunction cast_aggregate_function(f: string): string {\n  switch (f) {\n    case 'avg':\n    case 'max':\n    case 'min':\n    case 'sum':\n    case 'total':\n      return f;\n    default:\n      throw new Error(\n        `Aggregate function ${f} is not supported by SQLite. See: https://www.sqlite.org/lang_aggfunc.html`,\n      );\n  }\n}\n\n/**\n * Builds an Aggregate query expression.\n */\nfunction aggregates_query(\n  allRelationships: Relationships[],\n  target: Target,\n  joinInfo: RelationshipJoinInfo | null,\n  aggregates: Aggregates,\n  wWhere: Expression | null,\n  wLimit: number | null,\n  wOffset: number | null,\n  wOrder: OrderBy | null,\n): string {","sourceCodeStart":413,"sourceCodeEnd":449,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/dc-agents/sqlite/src/query.ts#L413-L449","documentation":"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.","triggerScenarios":"Requesting an aggregate like `stddev`, `variance`, `median`, `array_agg`, or any vendor-specific aggregate (Postgres/BigQuery style) in the aggregates section of a query.","commonSituations":"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.","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"],"exampleFix":"// before\naggregates: { pops: { function: 'stddev', column: 'population' } }\n// after\naggregates: { pops: { function: 'avg', column: 'population' } }","handlingStrategy":"validation","validationCode":"const SQLITE_AGGS = new Set(['avg','count','group_concat','max','min','sum','total']);\nfor (const a of Object.values(aggregates)) if (!SQLITE_AGGS.has(a.function)) throw new Error(`Unsupported aggregate ${a.function}`);","typeGuard":"const isSqliteAggregate = (f: string): f is 'avg'|'count'|'group_concat'|'max'|'min'|'sum'|'total' => SQLITE_AGGS.has(f);","tryCatchPattern":null,"preventionTips":["Keep an allowlist of SQLite aggregates in client code","Don't port statistical aggregates from other engines; compute client-side"],"tags":["sqlite","aggregates","unsupported-function","query-builder"],"backgroundTag":"unsupported-aggregate-function","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}