{"record":{"id":"4d57d0422929f0c5","repo":"apache/cassandra","slug":"the-duration-must-have-a-day-precision-was-s","errorCode":null,"errorMessage":"The duration must have a day precision. Was: %s","messagePattern":"The duration must have a day precision\\. Was: (.+?)","errorType":"exception","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/SimpleDateType.java","lineNumber":119,"sourceCode":"    }\n\n    @Override\n    public CQL3Type asCQL3Type()\n    {\n        return CQL3Type.Native.DATE;\n    }\n\n    public TypeSerializer<Integer> getSerializer()\n    {\n        return SimpleDateSerializer.instance;\n    }\n\n    @Override\n    protected void validateDuration(Duration duration)\n    {\n        // Checks that the duration has no data below days.\n        if (!duration.hasDayPrecision())\n            throw invalidRequest(\"The duration must have a day precision. Was: %s\", duration);\n    }\n\n    @Override\n    public ByteBuffer getMaskedValue()\n    {\n        return MASKED_VALUE;\n    }\n}\n","sourceCodeStart":101,"sourceCodeEnd":128,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/SimpleDateType.java#L101-L128","documentation":"SimpleDateType models the CQL 'date' type, whose smallest unit is a day. When a duration value is validated for a date column, the duration must have day precision (no hours/minutes/seconds/nanos components); otherwise Cassandra rejects the write with this invalid-request error.","triggerScenarios":"Inserting or binding a Duration value into a 'date' column (e.g. via CQL literal like P1DT12H, or a driver Duration/ByteBuffer binding) where duration.hasDayPrecision() is false — i.e. the duration contains sub-day components.","commonSituations":"Developers mistaking the CQL 'duration' type semantics for 'date' arithmetic and inserting a duration like PT12H or P1DT2H into a date column; driver users constructing Durations with time components; migrating data that had time-of-day below days.","solutions":["Change the duration literal so it only contains day (and larger) components, e.g. use P1D instead of P1DT12H.","If sub-day precision is needed, change the column type to 'duration' or 'timestamp' instead of 'date'.","On the client, normalize the Duration by dropping time components before binding (verify with duration.hasDayPrecision())."],"exampleFix":"// before\nINSERT INTO events (day, lag) VALUES ('2024-01-01', P1DT12H);\n// after\nINSERT INTO events (day, lag) VALUES ('2024-01-01', P1D);","handlingStrategy":"validation","validationCode":"// Java (driver): verify day precision before binding a duration to a date column\nif (!duration.hasDayPrecision())\n    throw new IllegalArgumentException(\"Duration must have day precision for date columns: \" + duration);","typeGuard":null,"tryCatchPattern":"try {\n    session.execute(insert.bind(duration));\n} catch (InvalidQueryException e) {\n    if (e.getMessage().contains(\"day precision\")) {\n        // normalize and retry with day-only duration\n    }\n}","preventionTips":["Only use day-or-larger components (PnD / PnW / PnY PnM) in durations bound to date columns.","Never mix time components (H/M/S) into durations intended for date columns.","Consider using the 'duration' CQL type if sub-day precision is actually needed."],"tags":["cql","duration","type-validation"],"backgroundTag":"invalid-duration-format","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}