{"record":{"id":"69394c2e270ae4aa","repo":"prestodb/presto","slug":"syntax-error-69394c","errorCode":"SYNTAX_ERROR","errorMessage":"Cannot rename tables across catalogs","messagePattern":"Cannot rename tables across catalogs","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/metadata/MetadataManager.java","lineNumber":789,"sourceCode":"    {\n        ConnectorId partitioningConnectorId = partitioningMetadata.getPartitioningHandle().getConnectorId()\n                .orElseThrow(() -> new IllegalArgumentException(\"connectorId is expected to be present in the connector partitioning handle\"));\n        checkArgument(\n                connectorId.equals(partitioningConnectorId),\n                \"Unexpected partitioning handle connector: %s. Expected: %s.\",\n                partitioningConnectorId,\n                connectorId);\n        return new ConnectorPartitioningMetadata(partitioningMetadata.getPartitioningHandle().getConnectorHandle(), partitioningMetadata.getPartitionColumns());\n    }\n\n    @Override\n    public void renameTable(Session session, TableHandle tableHandle, QualifiedObjectName newTableName)\n    {\n        String catalogName = newTableName.getCatalogName();\n        CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogName);\n        ConnectorId connectorId = catalogMetadata.getConnectorId();\n        if (!tableHandle.getConnectorId().equals(connectorId)) {\n            throw new PrestoException(SYNTAX_ERROR, \"Cannot rename tables across catalogs\");\n        }\n\n        ConnectorMetadata metadata = catalogMetadata.getMetadata();\n\n        metadata.renameTable(session.toConnectorSession(connectorId), tableHandle.getConnectorHandle(),\n                toSchemaTableName(newTableName.getSchemaName(), newTableName.getObjectName()));\n    }\n\n    @Override\n    public void setTableProperties(Session session, TableHandle tableHandle, Map<String, Object> properties)\n    {\n        ConnectorId connectorId = tableHandle.getConnectorId();\n        ConnectorMetadata metadata = getMetadataForWrite(session, connectorId);\n        metadata.setTableProperties(session.toConnectorSession(connectorId), tableHandle.getConnectorHandle(), properties);\n    }\n\n    @Override\n    public void renameColumn(Session session, TableHandle tableHandle, ColumnHandle source, String target)","sourceCodeStart":771,"sourceCodeEnd":807,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/metadata/MetadataManager.java#L771-L807","documentation":"MetadataManager.renameTable rejects RENAME attempts where the destination qualified name belongs to a different catalog than the table's current connector. Presto cannot move a table between connectors, so cross-catalog renames throw SYNTAX_ERROR. Renames must stay within the same catalog (and hence the same connector).","triggerScenarios":"Running ALTER TABLE ... RENAME TO <catalog>.<other>.<name> (or calling renameTable) where newTableName.getCatalogName() differs from tableHandle.getConnectorId()'s catalog.","commonSituations":"Users attempting to 'move' a table from one catalog to another via rename; scripts that build fully-qualified target names dynamically; confusion between schemas (allowed) and catalogs (not allowed) during renames.","solutions":["Rename within the same catalog only: ALTER TABLE cat.db.old RENAME TO cat.db.new","To move data across catalogs, CREATE TABLE new_cat.db.new AS SELECT * FROM old_cat.db.old, then drop the source","Use a connector-specific export/import or storage-level copy for large cross-catalog moves","Update scripts to resolve the target catalog from the source table's catalog"],"exampleFix":"// before\nALTER TABLE hive.default.events RENAME TO iceberg.default.events; -- cross-catalog\n// after\nCREATE TABLE iceberg.default.events AS SELECT * FROM hive.default.events;\nDROP TABLE hive.default.events;","handlingStrategy":"validation","validationCode":"if (!newTableName.getCatalogName().equals(tableHandle.getConnectorId().getCatalogName())) {\n    throw new IllegalArgumentException(\"Rename target must stay in catalog \" + tableHandle.getConnectorId());\n}","typeGuard":"boolean sameCatalog(TableHandle h, QualifiedObjectName target) { return target.getCatalogName().equals(h.getConnectorId().getCatalogName()); }","tryCatchPattern":"try { metadataManager.renameTable(session, handle, newName); }\ncatch (PrestoException e) { if (SYNTAX_ERROR.getCode() == e.getErrorCode()) { /* fall back to CTAS + drop for cross-catalog moves */ } else throw e; }","preventionTips":["Only rename within the same catalog; use CTAS for cross-catalog moves","Generate target names in scripts from the source table's catalog","Educate users that schemas can differ but catalogs cannot on RENAME"],"tags":["presto","rename-table","sql","catalog"],"backgroundTag":"cross-catalog-rename-not-allowed","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"}