Apache DataFusion SQL Query Engine
Fix an issue with to_char signature not working correctly with timezones or other types because the ordering is not in most exact -> least exact order. (#13126)
Bruce Ritchie1c2a2fdcfe4e
diff --git a/datafusion/functions/src/datetime/to_char.rs b/datafusion/functions/src/datetime/to_char.rsindex 2fbfb22611..f0c4a02c15 100644--- a/datafusion/functions/src/datetime/to_char.rs+++ b/datafusion/functions/src/datetime/to_char.rs@@ -54,34 +54,34 @@ impl ToCharFunc {vec![Exact(vec![Date32, Utf8]),Exact(vec![Date64, Utf8]),+ Exact(vec![Time64(Nanosecond), Utf8]),+ Exact(vec![Time64(Microsecond), Utf8]),Exact(vec![Time32(Millisecond), Utf8]),Exact(vec![Time32(Second), Utf8]),- Exact(vec![Time64(Microsecond), Utf8]),- Exact(vec![Time64(Nanosecond), Utf8]),- Exact(vec![Timestamp(Second, None), Utf8]),Exact(vec![- Timestamp(Second, Some(TIMEZONE_WILDCARD.into())),+ Timestamp(Nanosecond, Some(TIMEZONE_WILDCARD.into())),Utf8,]),- Exact(vec![Timestamp(Millisecond, None), Utf8]),+ Exact(vec![Timestamp(Nanosecond, None), Utf8]),Exact(vec![- Timestamp(Millisecond, Some(TIMEZONE_WILDCARD.into())),+ Timestamp(Microsecond, Some(TIMEZONE_WILDCARD.into())),Utf8,]),Exact(vec![Timestamp(Microsecond, None), Utf8]),Exact(vec![- Timestamp(Microsecond, Some(TIMEZONE_WILDCARD.into())),+ Timestamp(Millisecond, Some(TIMEZONE_WILDCARD.into())),Utf8,]),- Exact(vec![Timestamp(Nanosecond, None), Utf8]),+ Exact(vec![Timestamp(Millisecond, None), Utf8]),Exact(vec![- Timestamp(Nanosecond, Some(TIMEZONE_WILDCARD.into())),+ Timestamp(Second, Some(TIMEZONE_WILDCARD.into())),Utf8,]),- Exact(vec![Duration(Second), Utf8]),- Exact(vec![Duration(Millisecond), Utf8]),- Exact(vec![Duration(Microsecond), Utf8]),+ Exact(vec![Timestamp(Second, None), Utf8]),Exact(vec![Duration(Nanosecond), Utf8]),+ Exact(vec![Duration(Microsecond), Utf8]),+ Exact(vec![Duration(Millisecond), Utf8]),+ Exact(vec![Duration(Second), Utf8]),],Volatility::Immutable,),diff --git a/datafusion/sqllogictest/test_files/timestamps.slt b/datafusion/sqllogictest/test_files/timestamps.sltindex d866ec8c94..38c2a66472 100644--- a/datafusion/sqllogictest/test_files/timestamps.slt+++ b/datafusion/sqllogictest/test_files/timestamps.slt@@ -2780,6 +2780,11 @@ FROMNULL01:01:2025 23-59-58+query T+select to_char('2020-01-01 00:10:20.123'::timestamp at time zone 'America/New_York', '%Y-%m-%d %H:%M:%S.%3f');+----+2020-01-01 00:10:20.123+statement okdrop table formats;