{"record":{"id":"ac59b2720b3b3f99","repo":"cube-js/cube","slug":"mysql-can-not-work-with-table-names-that-longer-th","errorCode":null,"errorMessage":"MySQL can not work with table names that longer than 64 symbols. Consider using the 'sqlAlias' attribute in your cube and in your pre-aggregation definition for ${name}.","messagePattern":"MySQL can not work with table names that longer than 64 symbols\\. Consider using the 'sqlAlias' attribute in your cube and in your pre-aggregation definition for (.+?)\\.","errorType":"validation","errorClass":"UserError","httpStatus":null,"severity":"error","filePath":"packages/cubejs-schema-compiler/src/adapter/MysqlQuery.ts","lineNumber":173,"sourceCode":"    return `SELECT TIMESTAMP(dates.f) date_from, TIMESTAMP(dates.t) date_to FROM (${values}) AS dates`;\n  }\n\n  public concatStringsSql(strings: string[]): string {\n    return `CONCAT(${strings.join(', ')})`;\n  }\n\n  public unixTimestampSql(): string {\n    return 'UNIX_TIMESTAMP()';\n  }\n\n  public wrapSegmentForDimensionSelect(sql: string): string {\n    return `IF(${sql}, 1, 0)`;\n  }\n\n  public preAggregationTableName(cube: string, preAggregationName: string, skipSchema: boolean): string {\n    const name = super.preAggregationTableName(cube, preAggregationName, skipSchema);\n    if (name.length > 64) {\n      throw new UserError(`MySQL can not work with table names that longer than 64 symbols. Consider using the 'sqlAlias' attribute in your cube and in your pre-aggregation definition for ${name}.`);\n    }\n    return name;\n  }\n\n  public supportGeneratedSeriesForCustomTd(): boolean {\n    return this.useGeneratedTimeSeries;\n  }\n\n  public intervalString(interval: string): string {\n    return this.formatInterval(interval);\n  }\n\n  public sqlTemplates() {\n    const templates = super.sqlTemplates();\n    templates.functions.STRING_AGG = 'GROUP_CONCAT({% if distinct %}DISTINCT {% endif %}{{ args[0] }} SEPARATOR {{ args[1] }})';\n    templates.functions.UTCTIMESTAMP = 'UTC_TIMESTAMP()';\n    // DATEADD is being rewritten to DATE_ADD, which reports sub-day intervals in\n    // milliseconds. MySQL has no MILLISECOND unit, so those are scaled to microseconds","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-schema-compiler/src/adapter/MysqlQuery.ts#L155-L191","documentation":"MySQL table names are limited to 64 characters. The generated pre-aggregation table name (built from cube + pre-aggregation name + suffix) exceeds that, so MysqlQuery refuses to create it and tells you to shorten it via 'sqlAlias'. This is a UserError thrown before any SQL is sent.","triggerScenarios":"Calling preAggregationTableName for a cube/pre-aggregation whose combined identifier exceeds 64 characters, e.g. long cube names like 'fact_table_marketing_attribution_daily_events' with a long preAggregationName like 'main_by_user_country_and_date'.","commonSituations":"Deeply nested cube names derived from long source tables; auto-generated pre-aggregation names from rollup joins or Cube Store workflows; schemas migrated from databases with longer identifier limits to MySQL.","solutions":["Add sqlAlias: '<short-name>' to the pre-aggregation definition in the data model to control the table name length.","Shorten the cube name or preAggregationName in the schema files.","Rename the underlying table/cube hierarchy to use compact prefixes.","Check the generated name in the error message and keep cube+preagg names under ~50 chars combined."],"exampleFix":"// before\ncube('marketing_attribution_daily_event_facts', { preAggregations: { main_by_user_country_and_date: {...} } })\n// after\ncube('marketing_attribution_daily_event_facts', { preAggregations: { main_by_user_country_and_date: { sqlAlias: 'mkt_daily', ... } } })","handlingStrategy":"validation","validationCode":"const expectedName = `${cubeName.toLowerCase()}_${preAggName.toLowerCase()}_main`;\nif (expectedName.length > 64) {\n  throw new Error(`Add sqlAlias: pre-agg table name would be ${expectedName.length} chars (max 64)`);\n}","typeGuard":null,"tryCatchPattern":"try { await compilerApi.preAggregationsSchema(); } catch (e) { if (/MySQL can not work with table names that longer than 64/.test(e.message)) {\n  console.error(`Add sqlAlias for pre-aggregation named in: ${e.message}`); } throw e; }","preventionTips":["Keep cube + preAggregationName combined under ~50 characters","Set sqlAlias on every long-named pre-aggregation","Lint schema files for identifier length in CI","Watch for rollup-join generated names that concatenate cube names"],"tags":["mysql","pre-aggregation","identifier-length"],"backgroundTag":"table-name-too-long","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}