cube-js/cube · error · UserError

Can't resolve ${tableName}: '${schema}' does not exist

Error message

Can't resolve ${tableName}: '${schema}' does not exist

What it means

ScaffoldingSchema.resolveTableDefinition looks up a table in the loaded DB schema by splitting '<schema>.<table>'. When the schema (first segment) is not present in the introspected dbSchema, this UserError is thrown. It means the requested schema name does not match any schema returned by the driver's tablesSchema().

Source

Thrown at packages/cubejs-schema-compiler/src/scaffolding/ScaffoldingSchema.ts:216

      tableNames.map(tableName => {
        const [schema, table] = this.parseTableName(tableName);
        const tableDefinition = this.resolveTableDefinition(tableName);
        const definition: TableData = {
          schema, table, tableDefinition, tableName
        };
        const tableizeName = inflection.tableize(this.fixCase(table));
        const parts = tableizeName.split('_');
        const tableNamesFromParts = R.range(0, parts.length - 1).map(toDrop => inflection.tableize(R.drop(toDrop, parts).join('_')));
        const names = R.uniq([table, tableizeName].concat(tableNamesFromParts));
        return names.map(n => [n, definition]);
      })
    ) as any;
  }

  public resolveTableDefinition(tableName: TableName) {
    const [schema, table] = this.parseTableName(tableName);
    if (!this.dbSchema[schema]) {
      throw new UserError(`Can't resolve ${tableName}: '${schema}' does not exist`);
    }
    if (!this.dbSchema[schema][table]) {
      throw new UserError(`Can't resolve ${tableName}: '${table}' does not exist`);
    }
    return this.dbSchema[schema][table];
  }

  protected tableSchema(tableName: TableName, includeJoins: boolean): TableSchema {
    const [schema, table] = this.parseTableName(tableName);
    const tableDefinition = this.resolveTableDefinition(tableName);
    const dimensions = this.dimensions(tableDefinition);

    return {
      cube: this.options.snakeCase ? toSnakeCase(table) : inflection.camelize(table),
      tableName,
      schema,
      table,
      measures: this.numberMeasures(tableDefinition),

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Print Object.keys of the driver's tablesSchema() and confirm the schema name exists
  2. Correct the schema portion of the table name to match the introspected schema exactly
  3. Grant the DB user access to the schema so the driver can introspect it
  4. Pass the table name as an explicit ['schema','table'] array to avoid parsing/quoting issues

Example fix

// before
schema.resolveTableDefinition('pubic.orders');
// after
schema.resolveTableDefinition('public.orders');
Defensive patterns

Strategy: validation

Validate before calling

const tablesSchema = await driver.tablesSchema();
if (!tablesSchema[schemaName]) throw new Error(`Schema '${schemaName}' not found; available: ${Object.keys(tablesSchema).join(', ')}`);

Type guard

const hasSchema = (s: any, name: string): s is { [k: string]: any } => typeof s === 'object' && s != null && name in s;

Try / catch

try { schema.resolveTableDefinition(tableName); } catch (e) { if (e instanceof UserError && /does not exist/.test(e.message)) { /* re-list schemas / prompt user */ } else throw e; }

Prevention

When it happens

Trigger: Calling resolveTableName/tableDefinition (directly or via scaffolding/generate-schema flows) with a table name whose schema portion is misspelled, quoted incorrectly, or absent from the driver's introspection results.

Common situations: Typos in schema names ('public' vs 'publi'), querying a custom Postgres schema not exposed to the DB user, default schema mismatches across data sources, or case-sensitivity issues where the actual schema is 'Public' or quoted lowercase.

Related errors


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