{"record":{"id":"ce9a5e06427ffb08","repo":"cube-js/cube","slug":"postgresql-can-not-work-with-table-names-longer-th","errorCode":null,"errorMessage":"PostgreSQL can not work with table names longer than 63 symbols. Consider using the 'sqlAlias' attribute in your cube definition for ${quotedTableName}.","messagePattern":"PostgreSQL can not work with table names longer than 63 symbols\\. Consider using the 'sqlAlias' attribute in your cube definition for (.+?)\\.","errorType":"exception","errorClass":"PostgresError","httpStatus":null,"severity":"error","filePath":"packages/cubejs-postgres-driver/src/PostgresDriver.ts","lineNumber":446,"sourceCode":"    PostgresDriver.checkValuesLimit(values);\n\n    return this.withConnection(async (conn) => {\n      await this.prepareConnection(conn);\n\n      const res = await conn.query({\n        text: query,\n        values: values || [],\n        types: {\n          getTypeParser: this.getTypeParser,\n        },\n      });\n      return res;\n    });\n  }\n\n  public async createTable(quotedTableName: string, columns: TableColumn[]): Promise<void> {\n    if (quotedTableName.length > 63) {\n      throw new PostgresError('PostgreSQL can not work with table names longer than 63 symbols. ' +\n        `Consider using the 'sqlAlias' attribute in your cube definition for ${quotedTableName}.`);\n    }\n    return super.createTable(quotedTableName, columns);\n  }\n\n  // eslint-disable-next-line @typescript-eslint/no-unused-vars\n  public async query<R = unknown>(query: string, values: unknown[], options?: QueryOptions): Promise<R[]> {\n    const result = await this.queryResponse(query, values);\n    return result.rows;\n  }\n\n  public async downloadQueryResults(query: string, values: unknown[], options: DownloadQueryResultsOptions): Promise<DownloadQueryResultsResult> {\n    if (options.streamImport) {\n      return this.stream(query, values, options);\n    }\n\n    const res = await this.queryResponse(query, values);\n    return {","sourceCodeStart":428,"sourceCodeEnd":464,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-postgres-driver/src/PostgresDriver.ts#L428-L464","documentation":"PostgreSQL identifiers (table names) are limited to 63 bytes by NAMEDATALEN. Cube's PostgresDriver checks the quoted table name length in createTable before issuing DDL and throws this error when a pre-aggregation table name would exceed that limit, since PostgreSQL would silently truncate it and break lookups. The error suggests using the 'sqlAlias' attribute in the cube definition to shorten generated names.","triggerScenarios":"uploadTableWithIndexes calls createTable with a quotedTableName longer than 63 characters — typically a long auto-generated pre-aggregation table name derived from a cube/alias with a very long name or deeply nested members.","commonSituations":"Cubes with long names or many long member names producing long pre-aggregation table identifiers; schemas whose names add to the quoted length; projects migrated to PostgreSQL without considering the 63-byte identifier limit.","solutions":["Add a short 'sqlAlias' attribute to the cube definition so generated pre-aggregation table names fit within 63 characters","Shorten the cube name or pre-aggregation name that produces the long table name","Reduce the schema name length so schema + table fits in 63 symbols"],"exampleFix":"// before\ncube('very_long_cube_name_that_generates_huge_preaggregation_table_identifiers', { ... });\n// after\ncube('very_long_cube_name_that_generates_huge_preaggregation_table_identifiers', {\n  sqlAlias: 'plg_sales', // short alias keeps table names under 63 chars\n  ...\n});","handlingStrategy":"validation","validationCode":"function assertTableFitsPgLimit(quotedTableName) {\n  if (quotedTableName.length > 63) {\n    throw new Error(`Table name exceeds PostgreSQL 63-char limit: ${quotedTableName.length} chars`);\n  }\n}\nassertTableFitsPgLimit('\"my_schema\".\"my_long_preaggregation_table_name\"');","typeGuard":"const isPgSafeIdentifier = (name) => typeof name === 'string' && name.length <= 63;","tryCatchPattern":"try {\n  await driver.createTable(quotedTableName, columns);\n} catch (e) {\n  if (String(e.message).includes('longer than 63 symbols')) {\n    console.error('Add sqlAlias to the cube definition to shorten table names');\n  }\n  throw e;\n}","preventionTips":["Always define a short sqlAlias for cubes with long names","Keep cube and pre-aggregation names short when targeting PostgreSQL","Add a CI check that generated table identifiers stay under 63 characters"],"tags":["postgresql","identifier-length","pre-aggregations","schema"],"backgroundTag":"identifier-too-long","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}