{"record":{"id":"369d22785f764082","repo":"apache/cassandra","slug":"there-are-duplicate-constraint-definitions-on-colu-369d22","errorCode":null,"errorMessage":"There are duplicate constraint definitions on column '%s': %s","messagePattern":"There are duplicate constraint definitions on column '(.+?)': (.+?)","errorType":"validation","errorClass":"InvalidConstraintDefinitionException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/constraints/ColumnConstraints.java","lineNumber":194,"sourceCode":"        public void checkSatisfiability(List<ColumnConstraint<?>> constraints, ColumnMetadata columnMetadata)\n        {\n            Set<String> constraintNames = new TreeSet<>();\n            List<String> duplicateConstraints = new ArrayList<>();\n\n            for (ColumnConstraint<?> constraint : constraints)\n            {\n                String constraintFullName = constraint.fullName();\n                String constraintName = constraint.name();\n\n                if (!constraintNames.add(constraintFullName))\n                {\n                    if (!constraint.enablesDuplicateDefinitions(constraintName))\n                        duplicateConstraints.add(constraintFullName);\n                }\n            }\n\n            if (!duplicateConstraints.isEmpty())\n                throw new InvalidConstraintDefinitionException(format(\"There are duplicate constraint definitions on column '%s': %s\",\n                                                                      columnMetadata.name,\n                                                                      duplicateConstraints));\n        }\n    }\n\n    private static class Noop extends ColumnConstraints\n    {\n        private Noop()\n        {\n            super(Collections.emptyList());\n        }\n\n        @Override\n        public void validate(ColumnMetadata columnMetadata)\n        {\n            // Do nothing. It is always valid\n        }\n","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/constraints/ColumnConstraints.java#L176-L212","documentation":"ColumnConstraints.checkSatisfiability detects when the same constraint (same constraint name enabling duplicates) is defined more than once on a single column, which would be ambiguous or redundant. It throws InvalidConstraintDefinitionException listing the column and the duplicated constraint names. This is schema-definition-time validation.","triggerScenarios":"A CREATE TABLE / ALTER TABLE statement specifies two constraints of the same kind on one column where the constraint's enablesDuplicateDefinitions() returns false — e.g. two identical LENGTH or JSON constraints on the same column.","commonSituations":"Hand-written DDL that repeats a constraint; schema migration scripts that re-add a constraint already present; generated DDL merging constraint lists without deduplication.","solutions":["Remove the duplicate constraint so each constraint appears once per column.","Merge duplicate constraints into a single one covering all needed checks (e.g. combine length bounds into one range).","Use a constraint implementation whose enablesDuplicateDefinitions() returns true if multiple instances are intentional."],"exampleFix":"// before\nname text CONSTRAINT CHECK LENGTH(1..10) CONSTRAINT CHECK LENGTH(1..20)\n// after\nname text CONSTRAINT CHECK LENGTH(1..20)","handlingStrategy":"validation","validationCode":"Map<String,Integer> counts = new HashMap<>();\nfor (ColumnConstraint<?> c : constraints)\n    counts.merge(c.name(), 1, Integer::sum);\nif (counts.values().stream().anyMatch(n -> n > 1)) throw new IllegalStateException(\"duplicate constraint definitions\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Deduplicate constraint lists in schema-builder code","Idempotent migration scripts: check for existing constraint before adding","Review hand-edited DDL for repeated CHECK clauses"],"tags":["cql","schema","constraints","duplicates"],"backgroundTag":"schema-validation-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}