prestodb/presto · error · SemanticException

MISSING_SCHEMA

MISSING_SCHEMA

Error message

Schema %s does not exist

What it means

When resolving table metadata and no TableHandle is found, MetadataUtils checks existence in order: catalog, then schema. If the catalog exists but the schema does not, it throws SemanticException MISSING_SCHEMA with the schema name. This tells the caller the namespace itself is absent rather than just the table.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/util/MetadataUtils.java:90

        }

        return session.getRuntimeStats().recordWallTime(
                GET_MATERIALIZED_VIEW_TIME_NANOS,
                () -> metadataResolver.getMaterializedView(viewName));
    }

    public static TableColumnMetadata getTableColumnMetadata(Session session, MetadataResolver metadataResolver, QualifiedObjectName tableName)
    {
        Optional<TableHandle> tableHandle = session.getRuntimeStats().recordWallTime(
                GET_TABLE_HANDLE_TIME_NANOS,
                () -> metadataResolver.getTableHandle(tableName));

        if (!tableHandle.isPresent()) {
            if (!metadataResolver.catalogExists(tableName.getCatalogName())) {
                throw new SemanticException(MISSING_CATALOG, "Catalog %s does not exist", tableName.getCatalogName());
            }
            if (!metadataResolver.schemaExists(new CatalogSchemaName(tableName.getCatalogName(), tableName.getSchemaName()))) {
                throw new SemanticException(MISSING_SCHEMA, "Schema %s does not exist", tableName.getSchemaName());
            }
            throw new SemanticException(MISSING_TABLE, "Table %s does not exist", tableName);
        }

        Map<String, ColumnHandle> columnHandles = session.getRuntimeStats().recordWallTime(
                GET_COLUMN_HANDLE_TIME_NANOS,
                () -> metadataResolver.getColumnHandles(tableHandle.get()));

        List<ColumnMetadata> columnsMetadata = session.getRuntimeStats().recordWallTime(
                GET_COLUMN_METADATA_TIME_NANOS,
                () -> metadataResolver.getColumns(tableHandle.get()));

        return new TableColumnMetadata(tableHandle, columnHandles, columnsMetadata);
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. List existing schemas: SHOW SCHEMAS FROM <catalog> and correct the name
  2. Create the schema if intended: CREATE SCHEMA <catalog>.<schema>
  3. Fix environment/config references pointing at the wrong schema
  4. Check case sensitivity requirements of the connector

Example fix

// before
SELECT * FROM postgresql.publik.orders;
// after
SELECT * FROM postgresql.public.orders;
Defensive patterns

Strategy: try-catch

Validate before calling

// Check schema existence before resolving table metadata
if (!metadata.listSchemaNames(session, catalogName).contains(schemaName)) {
    throw new IllegalArgumentException("Unknown schema: " + catalogName + "." + schemaName);
}

Try / catch

try {
    columns = MetadataUtils.getTableColumnMetadata(...);
} catch (SemanticException e) {
    if (e.getCode() == MISSING_SCHEMA) {
        throw new UserError("Unknown schema: " + e.getMessage());
    }
    throw e;
}

Prevention

When it happens

Trigger: Referencing catalog.schema.table where the catalog is configured but the schema name does not exist in that catalog, e.g. SELECT * FROM postgresql.publik.orders (typo) or querying a schema that was dropped.

Common situations: Typo in schema name; environment mismatch (dev vs prod schemas); schema dropped by migration while queries still reference it; wrong case-sensitive schema name for connectors like Hive or JDBC stores.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/a9d5644d05b7a30f. Report an issue: GitHub.