-
-
Notifications
You must be signed in to change notification settings - Fork 129
Description
Description and expected behavior
Executing a deep-nested query exceeds the 63 byte limit on identifiers in PostgreSQL.
Failed to execute query: Error: Failed to execute query: error: table name
"RepositoryCases$template$caseFields$caseField$fieldOptions$sub$"
specified more than once
Query that triggered it (ZenStack auto-generated hook useFindFirstRepositoryCases):
const { data } = useFindFirstRepositoryCases({
where: { id: caseId },
include: {
template: {
include: {
caseFields: {
include: {
caseField: {
include: {
fieldOptions: {
include: {
fieldOption: true // 5 levels deep
}
}
}
}
}
}
}
}
}
});
REST API endpoint: GET /api/model/repositoryCases/findFirst?q={...}
Server-side (ZenStack v3 RPCApiHandler): The handler receives this query and translates it to Kysely SQL, generating aliases like:
RepositoryCases$template$caseFields$caseField$fieldOptions$fieldOption (73 chars)
Why it fails: The generated alias RepositoryCases$template$caseFields$caseField$fieldOptions$fieldOption is 73 characters. PostgreSQL truncates at 63 chars (NAMEDATALEN-1). When ZenStack also generates a $sub variant, both truncate to the same 63 chars, causing the "table name specified more than once" error.
Schema models involved:
RepositoryCases -> template (Templates) -> caseFields (TemplateCaseAssignment) -> caseField (CaseFields) -> fieldOptions (CaseFieldAssignment) -> fieldOption (FieldOptions)