prestodb/presto · error · PrestoException

NOT_FOUND

NOT_FOUND

Error message

Schema not found: 

What it means

PrestoException (NOT_FOUND) thrown by ClickHouseClient.beginInsertTable when the schema (database) portion of the target table does not exist in ClickHouse. The check runs before opening a connection for the insert, so writes fail fast with a clear message naming the missing schema.

Source

Thrown at presto-clickhouse/src/main/java/com/facebook/presto/plugin/clickhouse/ClickHouseClient.java:529

                quoted(clickHouseColumn.getColumnName()),
                quoted(newColumnName));

        try (Connection connection = connectionFactory.openConnection(identity)) {
            execute(connection, sql);
        }
        catch (SQLException e) {
            PrestoException exception = new PrestoException(JDBC_ERROR, "Query: " + sql, e);
            throw exception;
        }
    }

    public ClickHouseOutputTableHandle beginInsertTable(ConnectorTableMetadata tableMetadata, ConnectorSession session, String tableName)
            throws SQLException
    {
        SchemaTableName schemaTableName = tableMetadata.getTable();
        ClickHouseIdentity identity = ClickHouseIdentity.from(session);
        if (!getSchemaNames(identity).contains(schemaTableName.getSchemaName())) {
            throw new PrestoException(NOT_FOUND, "Schema not found: " + schemaTableName.getSchemaName());
        }

        try (Connection connection = connectionFactory.openConnection(identity)) {
            boolean uppercase = connection.getMetaData().storesUpperCaseIdentifiers();
            String remoteSchema = toRemoteSchemaName(session, identity, connection, schemaTableName.getSchemaName());
            String remoteTable = toRemoteTableName(session, identity, connection, remoteSchema, schemaTableName.getTableName());
            if (uppercase) {
                tableName = tableName.toUpperCase(ENGLISH);
            }
            String catalog = connection.getCatalog();

            ImmutableList.Builder<String> columnNames = ImmutableList.builder();
            ImmutableList.Builder<Type> columnTypes = ImmutableList.builder();
            ImmutableList.Builder<String> columnList = ImmutableList.builder();
            for (ColumnMetadata column : tableMetadata.getColumns()) {
                String columnName = column.getName();
                if (uppercase) {
                    columnName = columnName.toUpperCase(ENGLISH);

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Verify the schema exists: SHOW CREATE SCHEMA / SHOW SCHEMAS in the ClickHouse catalog.
  2. Correct the schema name in your INSERT statement.
  3. Create the missing database in ClickHouse (CREATE DATABASE).
  4. Check the connector's case-sensitive-name-mapping setting if the schema exists with different case.
  5. Confirm you are querying the intended catalog.

Example fix

-- before
INSERT INTO clickhouse.wrong_schema.events SELECT * FROM events;
-- after
INSERT INTO clickhouse.analytics.events SELECT * FROM events;
Defensive patterns

Strategy: validation

Validate before calling

-- verify the schema exists before INSERT
SHOW SCHEMAS FROM clickhouse LIKE 'analytics';
-- must return the schema used in clickhouse.analytics.events

Try / catch

try {
    insertData(...);
} catch (PrestoException e) {
    if (e.getMessage().startsWith("Schema not found")) {
        execute("CREATE SCHEMA IF NOT EXISTS clickhouse." + schemaName);
        // then retry the insert once
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: INSERT into a catalog.schema.table where schemaTableName.getSchemaName() is not in getSchemaNames(identity); inserting into a table created in a database that was dropped or that never existed.

Common situations: Typo in the schema name in INSERT statements; using the wrong catalog mapping; ClickHouse database dropped between table creation and insert; case mismatch when case-insensitive name mapping is disabled.

Understand the failure class

Background: NOT_FOUND error code: why tRPC, Harbor, Nacos and other libraries return 404 "not found" errors for resources that may still exist — this error's family across 11 libraries.

Related errors


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