cube-js/cube · error · Error

Default database should be defined to be used for temporary

Error message

Default database should be defined to be used for temporary tables during query results downloads

What it means

A configuration guard in AuroraServerlessMySqlDriver.downloadQueryResults: the download flow materializes results into a temporary table in the current database, and with the Data API there is no explicit session database, so config.database (default DB) must be set to know where to create the temp table. It fires when the driver is used for query-results download without a configured default database.

Source

Thrown at packages/cubejs-mysql-aurora-serverless-driver/driver/AuroraServerlessMySqlDriver.js:128

  }

  fromGenericType(columnType) {
    return GenericTypeToMySql[columnType] || super.fromGenericType(columnType);
  }

  loadPreAggregationIntoTable(preAggregationTableName, loadSql, params, tx) {
    if (this.config.loadPreAggregationWithoutMetaLock) {
      return this.cancelCombinator(async saveCancelFn => {
        await saveCancelFn(this.query(`${loadSql} LIMIT 0`, params));
        await saveCancelFn(this.query(loadSql.replace(/^CREATE TABLE (\S+) AS/i, 'INSERT INTO $1'), params));
      });
    }
    return super.loadPreAggregationIntoTable(preAggregationTableName, loadSql, params, tx);
  }

  async downloadQueryResults(query, values) {
    if (!this.config.database) {
      throw new Error('Default database should be defined to be used for temporary tables during query results downloads');
    }
    const tableName = crypto.randomBytes(10).toString('hex');

    const transaction = this.dataApi.transaction()
      .query(`CREATE TEMPORARY TABLE \`${this.config.database}\`.t_${tableName} AS ${query} LIMIT 0`, values)
      .query(`DESCRIBE \`${this.config.database}\`.t_${tableName}`)
      .query(`DROP TEMPORARY TABLE \`${this.config.database}\`.t_${tableName}`)
      .rollback((error) => { if (error) throw new Error(error); });

    const results = await transaction.commit();
    const columns = results[1].records;

    const types = columns.map(c => ({ name: c.Field, type: this.toGenericType(c.Type) }));

    return {
      rows: await this.query(query, values),
      types,
    };

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Set the database option in the driver configuration (e.g. CUBEJS_DB_NAME) since downloadQueryResults creates a temporary table in the default database
  2. Pass the database name in the Aurora Serverless data store configuration so temp tables for downloads have a schema to live in
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/cubejs-mysql-aurora-serverless-driver/driver/AuroraServerlessMySqlDriver.js:128 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02). Data as JSON: /api/errors/9412216b8fe94235. Report an issue: GitHub.