{"record":{"id":"700d8bde160447f4","repo":"cube-js/cube","slug":"create-table-failed-e","errorCode":null,"errorMessage":"Create table failed: ${e}","messagePattern":"Create table failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cubejs-clickhouse-driver/src/ClickHouseDriver.ts","lineNumber":599,"sourceCode":"\n    return columns.map((column) => ({\n      name: column.name,\n      type: this.toGenericType(column.type),\n    }));\n  }\n\n  // This is only for use in tests\n  public override async createTableRaw(query: string): Promise<void> {\n    await this.command(query);\n  }\n\n  public override async createTable(quotedTableName: string, columns: TableColumn[]) {\n    const createTableSql = this.createTableSql(quotedTableName, columns);\n    try {\n      await this.command(createTableSql);\n    } catch (e) {\n      // TODO replace string formatting with proper cause\n      throw new Error(`Create table failed: ${e}`);\n    }\n  }\n\n  /**\n   * We use unloadWithoutTempTable strategy\n   */\n  public async unload(_tableName: string, options: UnloadOptions): Promise<DownloadTableCSVData> {\n    if (!options.query?.sql) {\n      throw new Error('Query must be defined in options');\n    }\n\n    return this.unloadFromQuery(\n      options.query?.sql,\n      options.query?.params,\n      options\n    );\n  }\n","sourceCodeStart":581,"sourceCodeEnd":617,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-clickhouse-driver/src/ClickHouseDriver.ts#L581-L617","documentation":"createTable() executes the generated CREATE TABLE statement via command() and wraps any failure in this generic error, losing the original cause via string interpolation. The failure is almost always a SQL-level problem with the DDL ClickHouse rejected.","triggerScenarios":"Driver.createTable(quotedTableName, columns) called during pre-aggregation load; command(createTableSql) rejects — table already exists, invalid engine options, bad column type mapping, or insufficient permissions.","commonSituations":"Resuming a failed load where the pre-aggregation table already exists; ClickHouse user lacking CREATE TABLE privilege on the target database; unsupported column types produced by toGenericType mapping; syntax differences across ClickHouse versions.","solutions":["Read the interpolated `${e}` text for the exact ClickHouse SQL error (e.g. 'Table already exists' vs 'Access denied')","Check for a leftover pre-aggregation table with the same name and drop it or let Cube rename/rebuild","Grant CREATE/DDL privileges on the target database to the ClickHouse user","Inspect the generated SQL (createTableSql) for unsupported column types and adjust data types in the data model","Upgrade driver/ClickHouse if the DDL uses syntax unsupported by your server version"],"exampleFix":"// before\nthrow new Error(`Create table failed: ${e}`);\n// after (in driver)\nthrow new Error(`Create table failed: ${e}`, { cause: e });","handlingStrategy":"try-catch","validationCode":"// Confirm DDL rights before a load run\nawait driver.query('SHOW GRANTS FOR CURRENT_USER', []);","typeGuard":"null","tryCatchPattern":"try { await driver.createTable(name, columns); }\ncatch (e) {\n  const cause = String(e.message);\n  if (cause.includes('ALREADY_EXISTS') || cause.includes('already exists')) { /* drop or reuse table */ }\n  if (cause.includes('ACCESS_DENIED')) throw new Error('Grant CREATE TABLE privilege to the Cube user', { cause: e });\n  throw e;\n}","preventionTips":["Grant CREATE/DROP DDL privileges on the pre-aggregation database","Clean up orphaned pre-aggregation tables after failed loads","Check the interpolated cause text for the exact ClickHouse SQL error"],"tags":["clickhouse","ddl","pre-aggregation","permissions","error-wrapping"],"backgroundTag":"create-table-failed","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}