prestodb/presto · error · SemanticException

NOT_SUPPORTED

NOT_SUPPORTED

Error message

USE statement is not supported

What it means

Presto does not implement the SQL USE statement (e.g. USE catalog.schema or USE schema). During semantic analysis, StatementAnalyzer.visitUse unconditionally throws a SemanticException with code NOT_SUPPORTED, because query session/catalog/schema selection in Presto is done at the connection/session level, not via SQL statements. The statement is rejected before any further analysis.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java:508

        }

        public Scope process(Node node, Optional<Scope> scope)
        {
            Scope returnScope = super.process(node, scope);
            checkState(returnScope.getOuterQueryParent().equals(outerQueryScope), "result scope should have outer query scope equal with parameter outer query scope");
            scope.ifPresent(value -> checkState(hasScopeAsLocalParent(returnScope, value), "return scope should have context scope as one of ancestors"));
            return returnScope;
        }

        private Scope process(Node node, Scope scope)
        {
            return process(node, Optional.of(scope));
        }

        @Override
        protected Scope visitUse(Use node, Optional<Scope> scope)
        {
            throw new SemanticException(NOT_SUPPORTED, node, "USE statement is not supported");
        }

        @Override
        protected Scope visitInsert(Insert insert, Optional<Scope> scope)
        {
            QualifiedObjectName targetTable = createQualifiedObjectName(session, insert, insert.getTarget(), metadata);

            MetadataHandle metadataHandle = analysis.getMetadataHandle();
            if (getViewDefinition(session, metadataResolver, metadataHandle, targetTable).isPresent()) {
                throw new SemanticException(NOT_SUPPORTED, insert, "Inserting into views is not supported");
            }

            if (getMaterializedViewDefinition(session, metadataResolver, metadataHandle, targetTable).isPresent()) {
                throw new SemanticException(NOT_SUPPORTED, insert, "Inserting into materialized views is not supported");
            }

            // analyze the query that creates the data
            Scope queryScope = process(insert.getQuery(), scope);

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Remove the USE statement and fully qualify table names (catalog.schema.table) in queries.
  2. Set the default catalog/schema on the session instead: JDBC URL parameter '?catalog=X&schema=Y' or SET SESSION equivalent via the client connection properties.
  3. If using the Presto CLI, pass --catalog and --schema flags at launch instead of issuing USE.
  4. If migrating a script generator, configure it to not emit USE for Presto targets.

Example fix

// before
Statement stmt = conn.createStatement();
stmt.execute("USE sales.europe");
stmt.execute("SELECT * FROM orders");

// after
// connect with jdbc:presto://host:8080/sales/europe
Statement stmt = conn.createStatement();
stmt.execute("SELECT * FROM sales.europe.orders");
Defensive patterns

Strategy: validation

Validate before calling

if (sql.trim().toUpperCase().startsWith("USE ")) {
    throw new IllegalArgumentException("Presto does not support USE; set catalog/schema on the connection instead");
}

Prevention

When it happens

Trigger: Executing a 'USE <schema>' or 'USE <catalog>.<<schema>' statement through Presto (via JDBC execute, CLI, or any client submitting a Use node). StatementAnalyzer.visitUse always throws — there is no condition under which USE succeeds.

Common situations: Migrating SQL scripts from MySQL, SQL Server, Hive CLI, or Spark where 'USE db' sets the default database; BI tools or ORM generators that emit USE before queries; copy-pasted legacy ETL scripts run against Presto.

Understand the failure class

Background: Presto NOT_SUPPORTED error: what "not supported" means and how to fix it — this error's family across 3 libraries.

Related errors


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