{"record":{"id":"dac4bf0dd8b17635","repo":"prestodb/presto","slug":"duplicate-column-name","errorCode":"DUPLICATE_COLUMN_NAME","errorMessage":"Column name '%s' specified more than once","messagePattern":"Column name '(.+?)' specified more than once","errorType":"error_code","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/execution/CreateTableTask.java","lineNumber":139,"sourceCode":"        boolean includingProperties = false;\n        List<TableConstraint<String>> constraints = new ArrayList<>();\n        for (TableElement element : statement.getElements()) {\n            if (element instanceof ColumnDefinition) {\n                ColumnDefinition column = (ColumnDefinition) element;\n                String columnName = column.getName().getValue();\n                String name = metadata.normalizeIdentifier(session, tableName.getCatalogName(), columnName);\n                Type type;\n                try {\n                    type = metadata.getType(parseTypeSignature(column.getType()));\n                }\n                catch (IllegalArgumentException | UnknownTypeException e) {\n                    throw new SemanticException(TYPE_MISMATCH, element, \"Unknown type '%s' for column '%s'\", column.getType(), column.getName());\n                }\n                if (type.equals(UNKNOWN)) {\n                    throw new SemanticException(TYPE_MISMATCH, element, \"Unknown type '%s' for column '%s'\", column.getType(), column.getName());\n                }\n                if (columns.containsKey(name)) {\n                    throw new SemanticException(DUPLICATE_COLUMN_NAME, column, \"Column name '%s' specified more than once\", column.getName());\n                }\n                if (!column.isNullable() && !metadata.getConnectorCapabilities(session, connectorId).contains(NOT_NULL_COLUMN_CONSTRAINT)) {\n                    throw new SemanticException(NOT_SUPPORTED, column, \"Catalog '%s' does not support non-null column for column name '%s'\", connectorId.getCatalogName(), column.getName());\n                }\n\n                Map<String, Expression> sqlProperties = mapFromProperties(column.getProperties());\n                Map<String, Object> columnProperties = metadata.getColumnPropertyManager().getProperties(\n                        connectorId,\n                        tableName.getCatalogName(),\n                        sqlProperties,\n                        session,\n                        metadata,\n                        parameterLookup);\n\n                columns.put(name, ColumnMetadata.builder()\n                        .setName(name)\n                        .setType(type)\n                        .setNullable(column.isNullable())","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/execution/CreateTableTask.java#L121-L157","documentation":"CreateTableTask.internalExecute throws SemanticException(DUPLICATE_COLUMN_NAME) when two column definitions normalize to the same name (columns.containsKey(name) after metadata.normalizeIdentifier). Duplicate column names make the resulting table schema ambiguous, so creation is rejected.","triggerScenarios":"CREATE TABLE listing the same column name twice, or two names that normalize to the same key (case-insensitive/normalized identifiers, e.g. 'Id' and 'ID').","commonSituations":"Copy-pasted column lists that duplicate a column; generated DDL merging multiple sources with overlapping names; case-differing names in case-insensitive catalogs.","solutions":["Remove or rename the duplicate column so all names are unique after normalization.","De-duplicate generated column lists before emitting DDL (e.g. LinkedHashMap keyed by normalized name).","Check identifier normalization rules of the target catalog to avoid case-collisions.","Validate the column list for duplicates before submitting the statement."],"exampleFix":"-- before\nCREATE TABLE t (id BIGINT, ID VARCHAR);\n\n-- after\nCREATE TABLE t (id BIGINT, id_label VARCHAR);","handlingStrategy":"validation","validationCode":"Map<String, Boolean> seen = new LinkedHashMap<>();\nfor (ColumnDefinition c : statement.getElements()) {\n    String name = metadata.normalizeIdentifier(session, catalog, c.getName());\n    if (!seen.putIfAbsent(name, true) == null) {\n        throw new IllegalStateException(\"Duplicate column after normalization: \" + name);\n    }\n}","typeGuard":"List<String> duplicateColumns(Session session, Metadata metadata, String catalog, List<ColumnDefinition> columns) {\n    Set<String> seen = new HashSet<>();\n    return columns.stream()\n        .map(c -> metadata.normalizeIdentifier(session, catalog, c.getName()))\n        .filter(n -> !seen.add(n))\n        .collect(Collectors.toList());\n}","tryCatchPattern":"try {\n    createTable(session, statement, parameters);\n} catch (SemanticException e) {\n    if (e.getCode() == DUPLICATE_COLUMN_NAME) {\n        // de-duplicate/rename columns and resubmit\n    } else {\n        throw e;\n    }\n}","preventionTips":["De-duplicate column lists by normalized name in DDL generators","Remember identifiers normalize case-insensitively in many catalogs — 'Id' and 'ID' collide","Unit-test generated schemas for duplicate normalized names","Review merged column definitions from multiple sources for overlapping names"],"tags":["presto","ddl","duplicate-column","create-table","schema"],"backgroundTag":"duplicate-column-name","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"}