{"record":{"id":"c7859a2529709403","repo":"apache/cassandra","slug":"there-are-duplicate-constraint-definitions-on-colu","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/AbstractFunctionSatisfiabilityChecker.java","lineNumber":113,"sourceCode":"    private void checkNumberOfConstraints(ColumnMetadata columnMetadata, Pair<List<CONSTRAINT_TYPE>, List<CONSTRAINT_TYPE>> filteredConstraints)\n    {\n        List<? extends AbstractFunctionConstraint<CONSTRAINT_TYPE>> allConstraints = filteredConstraints.left;\n        List<? extends AbstractFunctionConstraint<CONSTRAINT_TYPE>> notEqualConstraints = filteredConstraints.right;\n\n        if ((allConstraints.size() - notEqualConstraints.size() > 2))\n        {\n            throw new InvalidConstraintDefinitionException(format(\"There can not be more than 2 constraints (not including non-equal relations) on a column '%s' but you have specified %s\",\n                                                                  columnMetadata.name,\n                                                                  allConstraints.size()));\n        }\n\n        if (notEqualConstraints.size() > 1)\n        {\n            Set<String> uniqueTerms = new TreeSet<>();\n            for (AbstractFunctionConstraint<CONSTRAINT_TYPE> notEqual : notEqualConstraints)\n            {\n                if (!uniqueTerms.add(notEqual.term()))\n                    throw new InvalidConstraintDefinitionException(format(\"There are duplicate constraint definitions on column '%s': %s\",\n                                                                          columnMetadata.name,\n                                                                          notEqual));\n            }\n        }\n    }\n\n    private void ensureSatisfiability(ColumnMetadata columnMetadata,\n                                      String constraintName,\n                                      List<CONSTRAINT_TYPE> allConstraints)\n    {\n        if (allConstraints.size() != 2)\n            return;\n\n        Operator firstRelation = allConstraints.get(0).relationType();\n        String firstTerm = allConstraints.get(0).term();\n        Operator secondRelation = allConstraints.get(1).relationType();\n        String secondTerm = allConstraints.get(1).term();\n","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/constraints/AbstractFunctionSatisfiabilityChecker.java#L95-L131","documentation":"When multiple NEQ (non-equal) constraints exist on one column, the checker collects their terms into a TreeSet; if the same term appears twice, the constraint definitions are redundant, and InvalidConstraintDefinitionException is thrown naming the column and the duplicate constraint. Detected at schema-definition time in checkNumberOfConstraints.","triggerScenarios":"CREATE TABLE/ALTER TABLE with two identical NEQ CHECK constraints on the same column, e.g. CHECK status != 'x' AND status != 'x'.","commonSituations":"Copy-paste mistakes when composing CHECK clauses; schema migrations appending a constraint that already exists; generated DDL emitting duplicates.","solutions":["Remove the duplicate NEQ constraint, keeping a single occurrence of each distinct term.","Diff the CREATE/ALTER TABLE DDL against the existing schema to spot already-present constraints.","Deduplicate terms programmatically if DDL is generated from a rules list."],"exampleFix":"// before\nCREATE TABLE t (status text CHECK status != 'draft' AND status != 'draft');\n// after\nCREATE TABLE t (status text CHECK status != 'draft');","handlingStrategy":"validation","validationCode":"Set<String> seen = new HashSet<>();\nfor (var c : neqConstraints) {\n    if (!seen.add(c.term())) throw new IllegalArgumentException(\"Duplicate NEQ term: \" + c.term());\n}","typeGuard":null,"tryCatchPattern":"try {\n    session.execute(schemaDdl);\n} catch (InvalidRequestException e) {\n    if (e.getMessage().contains(\"duplicate constraint definitions\")) {\n        log.error(\"Deduplicate CHECK constraints: {}\", e.getMessage());\n    } else throw e;\n}","preventionTips":["Deduplicate exclusion lists before generating DDL","Review diffs of generated schema files","Keep constraint definitions in one source of truth"],"tags":["cassandra","cql","constraints","duplicate"],"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"}