prestodb/presto · error · PrestoException

NOT_SUPPORTED

NOT_SUPPORTED

Error message

CREATE TABLE IF NOT EXISTS is not supported in this context 

What it means

Planning error: a CREATE TABLE IF NOT EXISTS (or INSERT-style CTAS no-op path) statement reached a planning context that does not support the IF NOT EXISTS no-op semantics (e.g. inside a distributed procedure or non-standard execution path), so the planner refuses to produce a plan for it.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/sql/planner/LogicalPlanner.java:210

        if (statement instanceof CreateTableAsSelect && analysis.isCreateTableAsSelectNoOp()) {
            checkState(analysis.getCreateTableDestination().isPresent(), "Table destination is missing");
            VariableReferenceExpression variable = variableAllocator.newVariable(getSourceLocation(statement), "rows", BIGINT);
            PlanNode source = new ValuesNode(
                    getSourceLocation(statement),
                    idAllocator.getNextId(),
                    ImmutableList.of(variable),
                    ImmutableList.of(ImmutableList.of(constant(0L, BIGINT))),
                    Optional.empty());
            return new OutputNode(source.getSourceLocation(), idAllocator.getNextId(), source, ImmutableList.of("rows"), ImmutableList.of(variable));
        }
        return createOutputPlan(planStatementWithoutOutput(analysis, statement), analysis);
    }

    private RelationPlan planStatementWithoutOutput(Analysis analysis, Statement statement)
    {
        if (statement instanceof CreateTableAsSelect) {
            if (analysis.isCreateTableAsSelectNoOp()) {
                throw new PrestoException(NOT_SUPPORTED, "CREATE TABLE IF NOT EXISTS is not supported in this context " + statement.getClass().getSimpleName());
            }
            return createTableCreationPlan(analysis, ((CreateTableAsSelect) statement).getQuery());
        }
        else if (statement instanceof Analyze) {
            return createAnalyzePlan(analysis, (Analyze) statement);
        }
        else if (statement instanceof Call) {
            Optional<DistributedProcedure.DistributedProcedureType> procedureType = analysis.getCallDistributedProcedureAnalysis()
                    .map(Analysis.CallDistributedProcedureAnalysis::getDistributedProcedureType);
            checkState(procedureType.isPresent(),
                    "Call distributed procedure analysis is missing");
            switch (procedureType.get()) {
                case TABLE_DATA_REWRITE:
                    return createCallDistributedProcedurePlanForTableDataRewrite(analysis, (Call) statement);
                default:
                    throw new PrestoException(NOT_SUPPORTED, "Unsupported distributed procedure type: " + procedureType.get());
            }
        }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Drop the IF NOT EXISTS clause and handle existence checks manually
  2. Check table existence first, then run a plain CREATE TABLE AS SELECT
  3. Use a supported execution context for the CTAS statement
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at presto-main-base/src/main/java/com/facebook/presto/sql/planner/LogicalPlanner.java:210 when the library encounters an invalid state.

Common situations: See trigger scenarios.

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.


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