{"record":{"id":"dca1d9b16058a3cd","repo":"prestodb/presto","slug":"column-already-exists-dca1d9","errorCode":"COLUMN_ALREADY_EXISTS","errorMessage":"Column '%s' already exists","messagePattern":"Column '(.+?)' already exists","errorType":"error_code","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/execution/RenameColumnTask.java","lineNumber":90,"sourceCode":"\n        Identifier sourceName = statement.getSource();\n        String source = metadata.normalizeIdentifier(session, tableName.getCatalogName(), sourceName.getValue());\n        Identifier targetName = statement.getTarget();\n        String target = metadata.normalizeIdentifier(session, tableName.getCatalogName(), targetName.getValue());\n\n        accessControl.checkCanRenameColumn(session.getRequiredTransactionId(), session.getIdentity(), session.getAccessControlContext(), tableName);\n\n        Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(session, tableHandle);\n        ColumnHandle columnHandle = columnHandles.get(source);\n        if (columnHandle == null) {\n            if (!statement.isColumnExists()) {\n                throw new SemanticException(MISSING_COLUMN, statement, \"Column '%s' does not exist\", source);\n            }\n            return immediateFuture(null);\n        }\n\n        if (columnHandles.containsKey(target)) {\n            throw new SemanticException(COLUMN_ALREADY_EXISTS, statement, \"Column '%s' already exists\", target);\n        }\n\n        if (metadata.getColumnMetadata(session, tableHandle, columnHandle).isHidden()) {\n            throw new SemanticException(NOT_SUPPORTED, statement, \"Cannot rename hidden column\");\n        }\n\n        metadata.renameColumn(session, tableHandle, columnHandle, target);\n\n        return immediateFuture(null);\n    }\n}\n","sourceCodeStart":72,"sourceCodeEnd":102,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/execution/RenameColumnTask.java#L72-L102","documentation":"SemanticException thrown by RenameColumnTask when the target column name of a RENAME COLUMN already exists in the table. Allowing the rename would create a duplicate column, so Presto rejects it. Rename the source to a name not present in the table's column handles.","triggerScenarios":"ALTER TABLE ... RENAME COLUMN where columnHandles.containsKey(target) is true, i.e. the destination name collides with an existing column.","commonSituations":"Destination name collides with an existing column (e.g. renaming 'id' to 'customer_id' when 'customer_id' already exists); migrating from systems that auto-suffix duplicates; partially-completed prior migration already added the target name.","solutions":["Choose a distinct target name that doesn't exist in the table","Drop or rename the conflicting existing column first","Check DESCRIBE table output to pick a non-colliding name","Add migration logic that verifies the source exists and target doesn't before issuing the rename"],"exampleFix":"-- before\nALTER TABLE shop.orders RENAME COLUMN id TO customer_id; -- customer_id exists\n-- after\nALTER TABLE shop.orders RENAME COLUMN id TO order_id; -- unique target","handlingStrategy":"validation","validationCode":"Set<String> cols = describeColumns(\"shop.orders\");\nif (cols.contains(\"customer_id\")) {\n    throw new IllegalStateException(\"target column customer_id already exists\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    execute(\"ALTER TABLE shop.orders RENAME COLUMN id TO customer_id\");\n} catch (SemanticException e) {\n    if (e.getCode() == COLUMN_ALREADY_EXISTS) { /* pick another name or drop conflict */ }\n    else throw e;\n}","preventionTips":["Check the destination name doesn't exist before renaming","Design migrations with unique, dated target names","Handle partially-completed migrations that may have already added the target column"],"tags":["presto","ddl","column-exists","name-conflict"],"backgroundTag":"resource-already-exists","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"}