hasura/graphql-engine · error · ErrorWithStatusCode
Can't create alias for functions
Error message
Can't create alias for functions
What it means
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.
Source
Thrown at dc-agents/sqlite/src/query.ts:364
): string {
switch (comparisonValue.type) {
case 'column':
return generateComparisonColumnFragment(
comparisonValue.column,
queryTableAlias,
currentTableAlias,
);
case 'scalar':
return escapeString(comparisonValue.value);
default:
return unreachable(comparisonValue['type']);
}
}
export function generateTargetAlias(target: Target): string {
switch (target.type) {
case 'function':
throw new ErrorWithStatusCode("Can't create alias for functions", 500, {
target,
});
case 'interpolated':
return generateTableAlias([target.id]);
case 'table':
return generateTableAlias(target.name);
}
}
function generateTableAlias(tableName: TableName): string {
return generateIdentifierAlias(validateTableName(tableName).join('_'));
}
function generateIdentifierAlias(identifier: string): string {
const randomSuffix = nanoid();
return escapeIdentifier(`${identifier}_${randomSuffix}`);
}
View on GitHub (pinned to 724551b9ae)
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
Example fix
// before
relationship: { target: { type: 'function', name: 'f' } }
// after
relationship: { target: { type: 'table', name: ['main','public','f_result'] } } Defensive patterns
Strategy: type-guard
Validate before calling
if (target.type === 'function') throw new Error('Cannot alias function targets'); Type guard
const isAliasableTarget = (t: Target): t is TableTarget | InterpolatedTarget => t.type !== 'function';
Prevention
- Pre-validate all targets in the tree including relationship targets
- Materialize function outputs as tables/views
When it happens
Trigger: Any query tree where a function target flows into alias generation — top-level target, relationship target, or join target — without having been rejected earlier.
Common situations: Function targets embedded in relationship chains; client code that generically wraps every entity as a target; metadata drift after adding tracked functions.
Related errors
- Can't execute table_query for UDFs
- `escapeTargetName` only implemented for tables and interpola
- User defined functions not supported in queries
- ${tableName.join('.')} is not a valid table
- Couldn't find relationship ${field.relationship} for field $
AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28).
Data as JSON: /api/errors/64d4e558e0240f25.
Report an issue: GitHub.