{"record":{"id":"974ed8d6fc22a7ac","repo":"risingwavelabs/risingwave","slug":"can-t-cast-string-to-timestamp-expected-format-is","errorCode":null,"errorMessage":"Can't cast string to timestamp (expected format is YYYY-MM-DD HH:MM:SS[.D+{up to 9 digits}] or YYYY-MM-DD HH:MM or YYYY-MM-DD or ISO 8601 format)","messagePattern":"Can't cast string to timestamp \\(expected format is YYYY-MM-DD HH:MM:SS\\[\\.D\\+(.+?)\\] or YYYY-MM-DD HH:MM or YYYY-MM-DD or ISO 8601 format\\)","errorType":"validation","errorClass":"InvalidParamsError","httpStatus":null,"severity":"error","filePath":"src/common/src/types/datetime.rs","lineNumber":265,"sourceCode":"#[derive(Copy, Clone, Debug, Error)]\nenum ErrorKind {\n    #[error(\"Invalid date: days: {days}\")]\n    Date { days: i32 },\n    #[error(\"Invalid time: secs: {secs}, nanoseconds: {nsecs}\")]\n    Time { secs: u32, nsecs: u32 },\n    #[error(\"Invalid time: {value} {unit} is out of range for a time of day\")]\n    TimeOfDay { value: u64, unit: &'static str },\n    #[error(\"Invalid datetime: seconds: {secs}, nanoseconds: {nsecs}\")]\n    DateTime { secs: i64, nsecs: u32 },\n    #[error(\"Invalid datetime: {value} {unit} is out of range\")]\n    Timestamp { value: i64, unit: &'static str },\n    #[error(\"Can't cast string to date (expected format is YYYY-MM-DD)\")]\n    ParseDate,\n    #[error(\n        \"Can't cast string to time (expected format is HH:MM:SS[.D+{{up to 6 digits}}][Z] or HH:MM)\"\n    )]\n    ParseTime,\n    #[error(\n        \"Can't cast string to timestamp (expected format is YYYY-MM-DD HH:MM:SS[.D+{{up to 9 digits}}] or YYYY-MM-DD HH:MM or YYYY-MM-DD or ISO 8601 format)\"\n    )]\n    ParseTimestamp,\n}\n\n#[derive(Debug, Error)]\n#[error(transparent)]\npub struct InvalidParamsError(#[from] ErrorKind);\n\nimpl InvalidParamsError {\n    pub fn date(days: i32) -> Self {\n        ErrorKind::Date { days }.into()\n    }\n\n    pub fn time(secs: u32, nsecs: u32) -> Self {\n        ErrorKind::Time { secs, nsecs }.into()\n    }\n","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/common/src/types/datetime.rs#L247-L283","documentation":"ErrorKind::ParseTimestamp is thrown by Timestamp::from_str when jiff's civil::DateTime parser rejects the input. Accepted shapes: 'YYYY-MM-DD HH:MM:SS[.up to 9 fractional digits]', 'YYYY-MM-DD HH:MM', 'YYYY-MM-DD', or ISO 8601 ('YYYY-MM-DDTHH:MM:SS').","triggerScenarios":"Casting strings such as '2024-01-15 04:05:06 PM', '15/01/2024 10:00', or Unix epoch integers to TIMESTAMP; epoch numbers must be converted numerically (with_millis/with_micros), not parsed as strings.","commonSituations":"CSV ingestion with US-style date ordering; passing epoch milliseconds as string and expecting implicit conversion; locale-specific month names (e.g. 'Jan 15, 2024 10:00').","solutions":["Convert epoch numbers via Timestamp::with_millis/with_micros instead of string parsing.","Reformat the string to 'YYYY-MM-DD HH:MM:SS' or ISO 8601 before casting.","Use an explicit parsing function with a format mask for non-ISO source layouts."],"exampleFix":"// before\nlet ts = Timestamp::from_str(\"1705315500000\")?;\n// after\nlet ts = Timestamp::with_millis(1705315500000)?;","handlingStrategy":"validation","validationCode":"fn is_parseable_timestamp(s: &str) -> bool {\n    let re = regex::Regex::new(r\"^\\d{4}-\\d{2}-\\d{2}([T ]\\d{2}:\\d{2}(:\\d{2}(\\.\\d{1,9})?)?)?$\").unwrap();\n    re.is_match(s.trim())\n}","typeGuard":"fn looks_like_timestamp(s: &str) -> bool {\n    s.trim().parse::<jiff::civil::DateTime>().is_ok()\n}","tryCatchPattern":"let ts = Timestamp::from_str(s)\n    .map_err(|e| anyhow!(\"'{s}' is not a supported timestamp format: {e}\"))?;","preventionTips":["Convert epoch numbers with with_millis/with_micros, never via string parsing.","Standardize on 'YYYY-MM-DD HH:MM:SS' or ISO 8601 at data entry points.","Reject locale-formatted dates upstream instead of relying on cast errors."],"tags":["rust","timestamp","parsing","sql-cast"],"backgroundTag":"invalid-date-format","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}