{"record":{"id":"64d4e558e0240f25","repo":"hasura/graphql-engine","slug":"can-t-create-alias-for-functions","errorCode":null,"errorMessage":"Can't create alias for functions","messagePattern":"Can't create alias for functions","errorType":"http","errorClass":"ErrorWithStatusCode","httpStatus":500,"severity":"error","filePath":"dc-agents/sqlite/src/query.ts","lineNumber":364,"sourceCode":"): string {\n  switch (comparisonValue.type) {\n    case 'column':\n      return generateComparisonColumnFragment(\n        comparisonValue.column,\n        queryTableAlias,\n        currentTableAlias,\n      );\n    case 'scalar':\n      return escapeString(comparisonValue.value);\n    default:\n      return unreachable(comparisonValue['type']);\n  }\n}\n\nexport function generateTargetAlias(target: Target): string {\n  switch (target.type) {\n    case 'function':\n      throw new ErrorWithStatusCode(\"Can't create alias for functions\", 500, {\n        target,\n      });\n    case 'interpolated':\n      return generateTableAlias([target.id]);\n    case 'table':\n      return generateTableAlias(target.name);\n  }\n}\n\nfunction generateTableAlias(tableName: TableName): string {\n  return generateIdentifierAlias(validateTableName(tableName).join('_'));\n}\n\nfunction generateIdentifierAlias(identifier: string): string {\n  const randomSuffix = nanoid();\n  return escapeIdentifier(`${identifier}_${randomSuffix}`);\n}\n","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/dc-agents/sqlite/src/query.ts#L346-L382","documentation":"generateTargetAlias produces a table alias for a target; functions are not tables and cannot be aliased, so a target of type 'function' triggers an ErrorWithStatusCode(500). This is reached from alias generation for joins, relationships, subqueries, and top-level targets.","triggerScenarios":"Any query tree where a function target flows into alias generation — top-level target, relationship target, or join target — without having been rejected earlier.","commonSituations":"Function targets embedded in relationship chains; client code that generically wraps every entity as a target; metadata drift after adding tracked functions.","solutions":["Replace the function target with a table or interpolated target throughout the request tree","Validate the whole request tree client-side before sending (walk every target and relationship target)","Upgrade the agent so function targets fail earlier with the clearer 'not supported in queries' message"],"exampleFix":"// before\nrelationship: { target: { type: 'function', name: 'f' } }\n// after\nrelationship: { target: { type: 'table', name: ['main','public','f_result'] } }","handlingStrategy":"type-guard","validationCode":"if (target.type === 'function') throw new Error('Cannot alias function targets');","typeGuard":"const isAliasableTarget = (t: Target): t is TableTarget | InterpolatedTarget => t.type !== 'function';","tryCatchPattern":null,"preventionTips":["Pre-validate all targets in the tree including relationship targets","Materialize function outputs as tables/views"],"tags":["sqlite","alias","target","udf","query-builder"],"backgroundTag":"unsupported-query-target","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}