Skip to content

[Bug] Query fails to execute when exceeding the PostgreSQL 63 byte limit on identifiers #2378

@therealbrad

Description

@therealbrad

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions