cube-js/cube · error · Error
Unknown dbType: ${dbType}
Error message
Unknown dbType: ${dbType} What it means
getSqlGenerator resolves a SQL generator (dialect class) based on the dataSource's dbType. If createQueryByDataSource returns nothing for that dbType, Cube does not know how to build queries for it, so this Error is thrown.
Source
Thrown at packages/cubejs-server-core/src/core/CompilerApi.ts:325
);
return new QueryFactory(cubeToQueryClass);
}
public async getDbType(dataSource: string = 'default'): Promise<string> {
return this.dbType({ dataSource });
}
public getDialectClass(dataSource: string = 'default', dbType: string): BaseQuery {
return this.dialectClass?.({ dataSource, dbType });
}
public async getSqlGenerator(query: NormalizedQuery, dataSource?: string): Promise<{ sqlGenerator: any; compilers: Compiler }> {
const dbType = await this.getDbType(dataSource);
const compilers = await this.getCompilers({ requestId: query.requestId });
let sqlGenerator = await this.createQueryByDataSource(compilers, query, dataSource, dbType);
if (!sqlGenerator) {
throw new Error(`Unknown dbType: ${dbType}`);
}
// sqlGenerator.dataSource can return undefined for query without members
// Queries like this are used by api-gateway to initialize SQL API
// At the same time, those queries should use concrete dataSource, so we should be good to go with it
dataSource = compilers.compiler.withQuery(sqlGenerator, () => sqlGenerator.dataSource);
if (dataSource !== undefined) {
const _dbType = await this.getDbType(dataSource);
if (dataSource !== 'default' && dbType !== _dbType) {
// TODO consider more efficient way than instantiating query
sqlGenerator = await this.createQueryByDataSource(
compilers,
query,
dataSource,
_dbType
);
if (!sqlGenerator) {View on GitHub (pinned to 7d981676b3)
Solutions
- Check the configured dbType (log this.getDbType(dataSource)) and correct it to a supported value like 'postgres', 'mysql', 'bigquery'
- Install the matching driver package (e.g. @cubejs-backend/postgres-driver) so its dialect registers
- Ensure the driver's dbType() returns the expected string
- If using a custom driver, register a corresponding query/dialect class
Example fix
// before dbType: 'psql' // after dbType: 'postgres'
Defensive patterns
Strategy: validation
Validate before calling
const SUPPORTED = ['postgres','mysql','mssql','bigquery','redshift','clickhouse','snowflake','databricks jdbc','duckdb','mongodb','elasticsearch','cubesql'];
const dbType = await driver.dbType();
if (!SUPPORTED.includes(dbType)) throw new Error(`Unsupported dbType '${dbType}'`); Type guard
const isSupportedDbType = (t: unknown): t is SupportedDbType => typeof t === 'string' && SUPPORTED_DB_TYPES.includes(t);
Try / catch
try { await compilerApi.getSqlGenerator(query, dataSource); } catch (e) { if (/Unknown dbType/.test(e.message)) { /* correct driver config */ } else throw e; } Prevention
- Set dbType explicitly in cubejs-server options
- Install the matching @cubejs-backend/<db>-driver package
- Verify driver.dbType() output for custom drivers
- Pin versions so dialect registration changes are deliberate
When it happens
Trigger: driverFactory/dbType configured with a value not in Cube's supported dialect registry, or a dataSource configured with a driver whose dbType has no registered query class.
Common situations: Typo like 'postgresdb' or 'psql' instead of 'postgres', custom/experimental driver without a matching dialect registration, or upgrading Cube where a dialect name changed.
Related errors
- Undefined dbType or dialectClass for '${cube}'
- Dialect for '${queryOptions.externalDbType}' is not found
- Can't find dialect for '${dataSource}' data source: ${_dbTyp
- A user-defined contextToApiScopes function returns an incons
- A user-defined contextToApiScopes function returns a wrong s
AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02).
Data as JSON: /api/errors/44e3de6b740413a1.
Report an issue: GitHub.