prestodb/presto · error · SemanticException

SCHEMA_NOT_SPECIFIED

SCHEMA_NOT_SPECIFIED

Error message

Schema must be specified when session schema is not set

What it means

SCHEMA_NOT_SPECIFIED semantic error thrown at the end of createCatalogSchemaName when a catalog name was resolved (from session or the given name) but no schema could be determined — the given name had no schema part and the session schema is unset. Presto requires a concrete catalog.schema pair.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/metadata/MetadataUtil.java:147

        if (schema.isPresent()) {
            List<Identifier> parts = schema.get().getOriginalParts();
            if (parts.size() > 2) {
                throw new SemanticException(INVALID_SCHEMA_NAME, node, "Too many parts in schema name: %s", schema.get());
            }
            if (parts.size() == 2) {
                catalogName = parts.get(0).getValue();
            }
            if (catalogName == null) {
                throw new SemanticException(CATALOG_NOT_SPECIFIED, node, "Catalog must be specified when session catalog is not set");
            }
            schemaName = metadata.normalizeIdentifier(session, catalogName, schema.get().getOriginalSuffix().getValue());
        }

        if (catalogName == null) {
            throw new SemanticException(CATALOG_NOT_SPECIFIED, node, "Catalog must be specified when session catalog is not set");
        }
        if (schemaName == null) {
            throw new SemanticException(SCHEMA_NOT_SPECIFIED, node, "Schema must be specified when session schema is not set");
        }

        return new CatalogSchemaName(catalogName, schemaName);
    }

    public static QualifiedObjectName createQualifiedObjectName(Session session, Node node, QualifiedName name, Metadata metadata)
    {
        BiFunction<String, String, String> normalizer = (catalogName, objectName) -> metadata.normalizeIdentifier(session, catalogName, objectName);
        return MetadataUtils.createQualifiedObjectName(session.getCatalog(), session.getSchema(), node, name, normalizer);
    }

    public static Optional<CatalogMetadata> getOptionalCatalogMetadata(Session session, TransactionManager transactionManager, String catalogName)
    {
        return transactionManager.getOptionalCatalogMetadata(session.getRequiredTransactionId(), catalogName);
    }

    public static Optional<TableHandle> getOptionalTableHandle(Session session, TransactionManager transactionManager, QualifiedObjectName table, Optional<ConnectorTableVersion> tableVersion)
    {

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Add the schema to the statement: CREATE SCHEMA catalog.schema
  2. Run USE catalog.schema to set both session catalog and schema
  3. Set the schema in the JDBC URL or session configuration

Example fix

-- before (catalog set, no session schema)
CREATE SCHEMA staging;
-- after
CREATE SCHEMA sales.staging;
Defensive patterns

Strategy: validation

Validate before calling

if (session.getSchema().isEmpty() && (schema.isEmpty() || schema.get().getOriginalParts().size() < 2)) {
    throw new IllegalArgumentException("Schema must be set in session or supplied as catalog.schema");
}

Type guard

boolean schemaResolvable(Session s, java.util.Optional<QualifiedName> schema) {
    return s.getSchema().isPresent() || (schema.isPresent() && schema.get().getOriginalParts().size() >= 1);
}

Try / catch

try {
    MetadataUtil.createCatalogSchemaName(session, node, schema, metadata);
} catch (SemanticException e) {
    if (e.getCode() == SCHEMA_NOT_SPECIFIED) {
        // require USE catalog.schema or a qualified name before retry
    }
}

Prevention

When it happens

Trigger: Calling createCatalogSchemaName with a name or session that yields catalogName != null but schemaName == null, e.g. session has catalog set but no schema, and the statement passes no schema qualifier.

Common situations: Session connected with catalog only (no USE of a schema) executing unqualified schema DDL; JDBC URL with catalog but no schema; clients that assume a default schema exists.

Related errors


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