Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

date_trunc drops timezone #5976

Closed
waitingkuo opened this issue Apr 12, 2023 · 4 comments · Fixed by #7614 or #7729
Closed

date_trunc drops timezone #5976

waitingkuo opened this issue Apr 12, 2023 · 4 comments · Fixed by #7614 or #7729
Labels
bug Something isn't working

Comments

@waitingkuo
Copy link
Contributor

waitingkuo commented Apr 12, 2023

Describe the bug

date_trunc drops timezone while the input is timestamptz

To Reproduce

select date_trunc('hour', timestamptz '2000-01-01T00:00:00Z');
+------------------------------------------------------+
| datetrunc(Utf8("hour"),Utf8("2000-01-01T00:00:00Z")) |
+------------------------------------------------------+
| 2000-01-01T00:00:00                                  |
+------------------------------------------------------+
1 row in set. Query took 0.002 seconds.

Expected behavior

2000-01-01T00:00:00Z

Additional context

No response

@waitingkuo waitingkuo added the bug Something isn't working label Apr 12, 2023
@waitingkuo
Copy link
Contributor Author

@tustvold i think this issue depends on #5952 as well

@Weijun-H
Copy link
Member

I am willing to handle this issue this weekend.

@Weijun-H
Copy link
Member

Weijun-H commented Jun 30, 2023

The problem probably does not arise from the usage of date_trunc, but rather from the utilization of timestamp and timestamptz.

❯ select  timestamp '2000-01-01T00:00:00+08:00';
+-----------------------------------+
| Utf8("2000-01-01T00:00:00+08:00") |
+-----------------------------------+
| 1999-12-31T16:00:00               |
+-----------------------------------+
1 row in set. Query took 0.000 seconds.
❯ select  timestamptz '2000-01-01T00:00:00+08:00';
+-----------------------------------+
| Utf8("2000-01-01T00:00:00+08:00") |
+-----------------------------------+
| 1999-12-31T16:00:00Z              |
+-----------------------------------+

But I did not find the related stuff about the timestamptz definition 🤔.

@tustvold
Copy link
Contributor

tustvold commented Jun 30, 2023

I think there are two related issues:

  • The output always lacks a timezone
  • The truncation should occur in the timestamp's timezone, not UTC
❯ set timezone to '+08:00';
0 rows in set. Query took 0.001 seconds.
❯ select  timestamptz '2000-01-01T00:00:00';
+-----------------------------+
| Utf8("2000-01-01T00:00:00") |
+-----------------------------+
| 2000-01-01T00:00:00+08:00   |
+-----------------------------+
❯ select date_trunc('day', timestamptz '2000-01-01T00:00:00');
+-----------------------------------------------------+
| date_trunc(Utf8("day"),Utf8("2000-01-01T00:00:00")) |
+-----------------------------------------------------+
| 1999-12-31T00:00:00                                 |
+-----------------------------------------------------+
1 row in set. Query took 0.002 seconds.

The output in the final case should be 2000-01-01T00:00:00+08:00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment