{"record":{"id":"ec54f4240c8f9402","repo":"prestodb/presto","slug":"syntax-error-ec54f4","errorCode":"SYNTAX_ERROR","errorMessage":"Constraint name '%s' specified more than once","messagePattern":"Constraint name '(.+?)' specified more than once","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/execution/CreateTableTask.java","lineNumber":208,"sourceCode":"                        });\n            }\n            else if (element instanceof ConstraintSpecification) {\n                accessControl.checkCanAddConstraints(session.getRequiredTransactionId(), session.getIdentity(), session.getAccessControlContext(), tableName);\n                constraints.add(convertToTableConstraint(metadata, session, connectorId, (ConstraintSpecification) element, warningCollector, query));\n            }\n            else {\n                throw new PrestoException(GENERIC_INTERNAL_ERROR, \"Invalid TableElement: \" + element.getClass().getName());\n            }\n        }\n\n        accessControl.checkCanCreateTable(session.getRequiredTransactionId(), session.getIdentity(), session.getAccessControlContext(), tableName);\n\n        constraints.stream()\n                .filter(c -> c.getName().isPresent())\n                .collect(Collectors.groupingBy(c -> c.getName().get(), Collectors.counting()))\n                .forEach((constraintName, count) -> {\n                    if (count > 1) {\n                        throw new PrestoException(SYNTAX_ERROR, format(\"Constraint name '%s' specified more than once\", constraintName));\n                    }\n                });\n\n        if (constraints.stream()\n                .filter(PrimaryKeyConstraint.class::isInstance)\n                .collect(Collectors.groupingBy(c -> c.getName().orElse(\"\"), Collectors.counting()))\n                .size() > 1) {\n            throw new PrestoException(SYNTAX_ERROR, \"Multiple primary key constraints are not allowed\");\n        }\n\n        Map<String, Expression> sqlProperties = mapFromProperties(statement.getProperties());\n        Map<String, Object> properties = metadata.getTablePropertyManager().getProperties(\n                connectorId,\n                tableName.getCatalogName(),\n                sqlProperties,\n                session,\n                metadata,\n                parameterLookup);","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/execution/CreateTableTask.java#L190-L226","documentation":"Two or more named constraints in the same CREATE TABLE share the same constraint name. After converting ConstraintSpecifications, the task groups named constraints and throws SYNTAX_ERROR if any name has count > 1.","triggerScenarios":"CREATE TABLE t (... , CONSTRAINT pk1 PRIMARY KEY (a), CONSTRAINT pk1 UNIQUE (b)); — any two constraints with identical names (primary key, unique, foreign key).","commonSituations":"Copy-pasting constraint blocks without renaming; templated DDL generators emitting the same placeholder constraint name; merging table definitions from multiple sources.","solutions":["Rename one of the duplicate constraints so all constraint names are unique.","Remove the redundant constraint if both are unintentionally identical.","Let the engine generate names by omitting the CONSTRAINT <name> clause where supported."],"exampleFix":"// before\nCREATE TABLE t (a BIGINT, b BIGINT, CONSTRAINT c1 PRIMARY KEY (a), CONSTRAINT c1 UNIQUE (b));\n// after\nCREATE TABLE t (a BIGINT, b BIGINT, CONSTRAINT c1 PRIMARY KEY (a), CONSTRAINT c2 UNIQUE (b));","handlingStrategy":"validation","validationCode":"Map<String, Long> counts = constraints.stream()\n    .filter(c -> c.getName().isPresent())\n    .collect(Collectors.groupingBy(c -> c.getName().get(), Collectors.counting()));\nif (counts.values().stream().anyMatch(n -> n > 1)) {\n    throw new IllegalArgumentException(\"duplicate constraint name\");\n}","typeGuard":"null","tryCatchPattern":"try {\n    future = createTableTask.execute(statement, ...);\n} catch (PrestoException e) {\n    if (e.getErrorCode() == SYNTAX_ERROR.toErrorCode() && e.getMessage().contains(\"Constraint name\")) {\n        // regenerate DDL with unique constraint names\n    }\n}","preventionTips":["Use unique, convention-based constraint names (table-prefixed) in DDL generators.","Lint generated DDL for duplicate CONSTRAINT identifiers.","Omit explicit constraint names when names are not needed downstream."],"tags":["presto","ddl","create-table","constraint","syntax-error"],"backgroundTag":"duplicate-constraint-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"}