Skip to content

Commit 1c2a2fd

Browse files
authored
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)
1 parent c03e260 commit 1c2a2fd

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

datafusion/functions/src/datetime/to_char.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,34 +54,34 @@ impl ToCharFunc {
5454
vec![
5555
Exact(vec![Date32, Utf8]),
5656
Exact(vec![Date64, Utf8]),
57+
Exact(vec![Time64(Nanosecond), Utf8]),
58+
Exact(vec![Time64(Microsecond), Utf8]),
5759
Exact(vec![Time32(Millisecond), Utf8]),
5860
Exact(vec![Time32(Second), Utf8]),
59-
Exact(vec![Time64(Microsecond), Utf8]),
60-
Exact(vec![Time64(Nanosecond), Utf8]),
61-
Exact(vec![Timestamp(Second, None), Utf8]),
6261
Exact(vec![
63-
Timestamp(Second, Some(TIMEZONE_WILDCARD.into())),
62+
Timestamp(Nanosecond, Some(TIMEZONE_WILDCARD.into())),
6463
Utf8,
6564
]),
66-
Exact(vec![Timestamp(Millisecond, None), Utf8]),
65+
Exact(vec![Timestamp(Nanosecond, None), Utf8]),
6766
Exact(vec![
68-
Timestamp(Millisecond, Some(TIMEZONE_WILDCARD.into())),
67+
Timestamp(Microsecond, Some(TIMEZONE_WILDCARD.into())),
6968
Utf8,
7069
]),
7170
Exact(vec![Timestamp(Microsecond, None), Utf8]),
7271
Exact(vec![
73-
Timestamp(Microsecond, Some(TIMEZONE_WILDCARD.into())),
72+
Timestamp(Millisecond, Some(TIMEZONE_WILDCARD.into())),
7473
Utf8,
7574
]),
76-
Exact(vec![Timestamp(Nanosecond, None), Utf8]),
75+
Exact(vec![Timestamp(Millisecond, None), Utf8]),
7776
Exact(vec![
78-
Timestamp(Nanosecond, Some(TIMEZONE_WILDCARD.into())),
77+
Timestamp(Second, Some(TIMEZONE_WILDCARD.into())),
7978
Utf8,
8079
]),
81-
Exact(vec![Duration(Second), Utf8]),
82-
Exact(vec![Duration(Millisecond), Utf8]),
83-
Exact(vec![Duration(Microsecond), Utf8]),
80+
Exact(vec![Timestamp(Second, None), Utf8]),
8481
Exact(vec![Duration(Nanosecond), Utf8]),
82+
Exact(vec![Duration(Microsecond), Utf8]),
83+
Exact(vec![Duration(Millisecond), Utf8]),
84+
Exact(vec![Duration(Second), Utf8]),
8585
],
8686
Volatility::Immutable,
8787
),

datafusion/sqllogictest/test_files/timestamps.slt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2780,6 +2780,11 @@ FROM
27802780
NULL
27812781
01:01:2025 23-59-58
27822782

2783+
query T
2784+
select to_char('2020-01-01 00:10:20.123'::timestamp at time zone 'America/New_York', '%Y-%m-%d %H:%M:%S.%3f');
2785+
----
2786+
2020-01-01 00:10:20.123
2787+
27832788
statement ok
27842789
drop table formats;
27852790

0 commit comments

Comments
 (0)