{"record":{"id":"59c3f4c201d815b8","repo":"prestodb/presto","slug":"not-supported-59c3f4","errorCode":"NOT_SUPPORTED","errorMessage":"'%s' is a materialized view, and drop constraint is not supported","messagePattern":"'(.+?)' is a materialized view, and drop constraint is not supported","errorType":"error_code","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/execution/DropConstraintTask.java","lineNumber":65,"sourceCode":"    }\n\n    @Override\n    public ListenableFuture<?> execute(DropConstraint statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, Session session, List<Expression> parameters, WarningCollector warningCollector, String query)\n    {\n        QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getTableName(), metadata);\n        Optional<TableHandle> tableHandleOptional = metadata.getMetadataResolver(session).getTableHandle(tableName);\n\n        if (!tableHandleOptional.isPresent()) {\n            if (!statement.isTableExists()) {\n                throw new SemanticException(MISSING_TABLE, statement, \"Table '%s' does not exist\", tableName);\n            }\n            return immediateFuture(null);\n        }\n\n        Optional<MaterializedViewDefinition> optionalMaterializedView = metadata.getMetadataResolver(session).getMaterializedView(tableName);\n        if (optionalMaterializedView.isPresent()) {\n            if (!statement.isTableExists()) {\n                throw new SemanticException(NOT_SUPPORTED, statement, \"'%s' is a materialized view, and drop constraint is not supported\", tableName);\n            }\n            return immediateFuture(null);\n        }\n\n        ConnectorId connectorId = metadata.getCatalogHandle(session, tableName.getCatalogName())\n                .orElseThrow(() -> new PrestoException(NOT_FOUND, \"Catalog does not exist: \" + tableName.getCatalogName()));\n        accessControl.checkCanDropConstraint(session.getRequiredTransactionId(), session.getIdentity(), session.getAccessControlContext(), tableName);\n\n        metadata.dropConstraint(session, tableHandleOptional.get(), Optional.of(statement.getConstraintName().toString()), Optional.empty());\n        return immediateFuture(null);\n    }\n}\n","sourceCodeStart":47,"sourceCodeEnd":78,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/execution/DropConstraintTask.java#L47-L78","documentation":"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).","triggerScenarios":"DROP CONSTRAINT executed against a name where metadata.getMetadataResolver(session).getMaterializedView(tableName) returns present and statement.isTableExists() is false.","commonSituations":"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.","solutions":["Check the relation type: SHOW CREATE VIEW / query system metadata to confirm it is a materialized view.","Drop and recreate the materialized view with the desired definition instead of altering constraints.","Skip materialized views in automation, or use IF EXISTS semantics to tolerate them."],"exampleFix":"// before\nDROP CONSTRAINT mv_catalog.db.sales_mv primary_key;\n// after\nDROP MATERIALIZED VIEW mv_catalog.db.sales_mv;\nCREATE MATERIALIZED VIEW mv_catalog.db.sales_mv AS SELECT ...;","handlingStrategy":"validation","validationCode":"-- check relation type before DROP CONSTRAINT\nSELECT table_type FROM <catalog>.information_schema.tables\nWHERE table_schema = 'db' AND table_name = 'sales_mv';\n-- if it is a MATERIALIZED VIEW, do not issue DROP CONSTRAINT","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Maintain a manifest of which relations are tables vs materialized views in automation.","Only generate constraint DDL for base tables.","Recreate materialized views to change their structure rather than altering constraints."],"tags":["sql","materialized-view","not-supported"],"backgroundTag":"operation-not-supported","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}