{"record":{"id":"837c64192fff0aec","repo":"apache/cassandra","slug":"column-value-does-not-satisfy-value-constraint-for-837c64","errorCode":null,"errorMessage":"Column value does not satisfy value constraint for column '<columnName>'. It has a length of <valueLength> and it should be should be <relationType> <term>","messagePattern":"Column value does not satisfy value constraint for column '<columnName>'\\. It has a length of <valueLength> and it should be should be <relationType> <term>","errorType":"validation","errorClass":"ConstraintViolationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/constraints/OctetLengthConstraint.java","lineNumber":51,"sourceCode":"{\n    private static final List<AbstractType<?>> SUPPORTED_TYPES = List.of(BytesType.instance, UTF8Type.instance, AsciiType.instance);\n\n    public OctetLengthConstraint(List<String> args)\n    {\n        super(\"OCTET_LENGTH\", args);\n    }\n\n    @Override\n    public void internalEvaluate(AbstractType<?> valueType, Operator relationType, String term, ByteBuffer columnValue)\n    {\n        int valueLength = columnValue.remaining();\n        int sizeConstraint = Integer.parseInt(term);\n\n        ByteBuffer leftOperand = ByteBufferUtil.bytes(valueLength);\n        ByteBuffer rightOperand = ByteBufferUtil.bytes(sizeConstraint);\n\n        if (!relationType.isSatisfiedBy(Int32Type.instance, leftOperand, rightOperand))\n            throw new ConstraintViolationException(\"Column value does not satisfy value constraint for column '\" + columnName + \"'. \"\n                                                   + \"It has a length of \" + valueLength + \" and it should be should be \"\n                                                   + relationType + ' ' + term);\n    }\n\n    @Override\n    public List<Operator> getSupportedOperators()\n    {\n        return DEFAULT_FUNCTION_OPERATORS;\n    }\n\n    @Override\n    public List<AbstractType<?>> getSupportedTypes()\n    {\n        return SUPPORTED_TYPES;\n    }\n\n    @Override\n    public boolean equals(Object o)","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/constraints/OctetLengthConstraint.java#L33-L69","documentation":"Thrown by OctetLengthConstraint.internalEvaluate when a column's byte length fails a declared LENGTH-based column constraint. Cassandra evaluates column constraints on every INSERT/UPDATE, and this exception surfaces as a ConstraintViolationException when the value's length does not satisfy the configured relation (e.g. LENGTH(col) >= 5).","triggerScenarios":"INSERT/UPDATE writes a value to a column with an octet-length constraint whose actual byte length does not satisfy the constraint's relationType against the term (e.g. constraint LENGTH(col) > 10 but value is 3 bytes).","commonSituations":"Schema declares min/max length constraints but application code sends short, empty, or oversized strings/blobs; multi-byte UTF-8 characters inflate byte length beyond the expected character count; truncation or padding changes upstream.","solutions":["Adjust the inserted value so its byte length satisfies the constraint (check LENGTH in cqlsh before writing).","ALTER the table to drop or relax the constraint if the length rule is wrong (DROP CONSTRAINT / re-add with correct term).","Validate value length in the application before issuing the write, accounting for UTF-8 byte length rather than character count."],"exampleFix":"// before: INSERT INTO t (id, name) VALUES (1, 'ab'); -- fails LENGTH(name) >= 5\n// after\nINSERT INTO t (id, name) VALUES (1, 'abcde');","handlingStrategy":"validation","validationCode":"// Java: check byte length before writing\nint len = value.getBytes(StandardCharsets.UTF_8).length; // or ByteBuffer.remaining()\nif (len < 5) throw new IllegalArgumentException(\"name must be >= 5 bytes, got \" + len);","typeGuard":null,"tryCatchPattern":"catch (ConstraintViolationException | InvalidRequestException e) { log.warn(\"length constraint violated: {}\", e.getMessage()); /* surface to caller */ }","preventionTips":["Mirror column constraints in application-side validators.","Compute UTF-8 byte length, not String.length(), for length checks.","Review constraints after schema changes with DESCRIBE TABLE."],"tags":["cassandra","cql","constraint-violation","validation"],"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"}