prestodb/presto · error · SemanticException

NOT_SUPPORTED

NOT_SUPPORTED

Error message

'%s' is a materialized view, and drop constraint is not supported

What it means

Thrown by DropConstraintTask.execute when the target object resolves to a materialized view. Constraint management is only supported on base tables, so Presto rejects the operation with NOT_SUPPORTED, unless IF EXISTS was specified (in which case it silently returns).

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/execution/DropConstraintTask.java:65

    }

    @Override
    public ListenableFuture<?> execute(DropConstraint statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, Session session, List<Expression> parameters, WarningCollector warningCollector, String query)
    {
        QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getTableName(), metadata);
        Optional<TableHandle> tableHandleOptional = metadata.getMetadataResolver(session).getTableHandle(tableName);

        if (!tableHandleOptional.isPresent()) {
            if (!statement.isTableExists()) {
                throw new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName);
            }
            return immediateFuture(null);
        }

        Optional<MaterializedViewDefinition> optionalMaterializedView = metadata.getMetadataResolver(session).getMaterializedView(tableName);
        if (optionalMaterializedView.isPresent()) {
            if (!statement.isTableExists()) {
                throw new SemanticException(NOT_SUPPORTED, statement, "'%s' is a materialized view, and drop constraint is not supported", tableName);
            }
            return immediateFuture(null);
        }

        ConnectorId connectorId = metadata.getCatalogHandle(session, tableName.getCatalogName())
                .orElseThrow(() -> new PrestoException(NOT_FOUND, "Catalog does not exist: " + tableName.getCatalogName()));
        accessControl.checkCanDropConstraint(session.getRequiredTransactionId(), session.getIdentity(), session.getAccessControlContext(), tableName);

        metadata.dropConstraint(session, tableHandleOptional.get(), Optional.of(statement.getConstraintName().toString()), Optional.empty());
        return immediateFuture(null);
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Check the relation type: SHOW CREATE VIEW / query system metadata to confirm it is a materialized view.
  2. Drop and recreate the materialized view with the desired definition instead of altering constraints.
  3. Skip materialized views in automation, or use IF EXISTS semantics to tolerate them.

Example fix

// before
DROP CONSTRAINT mv_catalog.db.sales_mv primary_key;
// after
DROP MATERIALIZED VIEW mv_catalog.db.sales_mv;
CREATE MATERIALIZED VIEW mv_catalog.db.sales_mv AS SELECT ...;
Defensive patterns

Strategy: validation

Validate before calling

-- check relation type before DROP CONSTRAINT
SELECT table_type FROM <catalog>.information_schema.tables
WHERE table_schema = 'db' AND table_name = 'sales_mv';
-- if it is a MATERIALIZED VIEW, do not issue DROP CONSTRAINT

Prevention

When it happens

Trigger: DROP CONSTRAINT executed against a name where metadata.getMetadataResolver(session).getMaterializedView(tableName) returns present and statement.isTableExists() is false.

Common situations: User assumes a materialized view is a regular table and tries to alter its constraints; a table was replaced by a materialized view of the same name; automation scripts that iterate over all relations in a schema.

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/59c3f4c201d815b8. Report an issue: GitHub.