apache/cassandra · error · InvalidRequestException
The duration must have a day precision. Was
Error message
The duration must have a day precision. Was: %s
What it means
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.
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()).
Example fix
// before
INSERT INTO events (day, lag) VALUES ('2024-01-01', P1DT12H);
// after
INSERT INTO events (day, lag) VALUES ('2024-01-01', P1D); Defensive patterns
Strategy: validation
Validate before calling
// Java (driver): verify day precision before binding a duration to a date column
if (!duration.hasDayPrecision())
throw new IllegalArgumentException("Duration must have day precision for date columns: " + duration); Try / catch
try {
session.execute(insert.bind(duration));
} catch (InvalidQueryException e) {
if (e.getMessage().contains("day precision")) {
// normalize and retry with day-only duration
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "invalid duration" / "failed to parse duration": why your timeout, interval, or TTL string is rejected and which formats each library accepts — this error's family across 32 libraries.
Related errors
- The duration must have a millisecond precision. Was
- Argument ' ' cannot be frozen; remove frozen<> modifier from
- duration type is not supported for PRIMARY KEY column
- Durations are not allowed as map keys:
- Durations are not allowed as map keys
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/4d57d0422929f0c5.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/db/marshal/SimpleDateType.java:119
}
@Override
public CQL3Type asCQL3Type()
{
return CQL3Type.Native.DATE;
}
public TypeSerializer<Integer> getSerializer()
{
return SimpleDateSerializer.instance;
}
@Override
protected void validateDuration(Duration duration)
{
// Checks that the duration has no data below days.
if (!duration.hasDayPrecision())
throw invalidRequest("The duration must have a day precision. Was: %s", duration);
}
@Override
public ByteBuffer getMaskedValue()
{
return MASKED_VALUE;
}
}
View on GitHub (pinned to 88fd0f6a0e)