-
-
Notifications
You must be signed in to change notification settings - Fork 214
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
Wrong DateTime insert #20
Comments
Can you provide sequence of CREATE TABLE/INSERT/SELECT operations in clickhouse-client and in clickhouse-driver? |
clickhouse_driver_test.py
My output:
|
It seems that this is driver's SELECT issue. From ClickHouse docs:
On INSERT datetime converts into timestamp. On SELECT timestamp converted into datetime with UTC timezone now. DateTime should be constructed using server or client timezone, not UTC. You can switch to UTC timezone as temporary solution. |
Moreover |
Another question: what for you call |
DateTime is stored as seconds since epoch, so we need to call |
Hello I propose this fix for this problem. https://gist.github.com/Thordin/c7442eb21839543e073ce9f2ca53dfd4 Any datetime with no timezone will be considered localtime and then changed to UTC when inserting into clickhouse. When you select datetime from database, it will be converted from UTC to the client's local timezone. This way you will get the same datetime as you inserted. If your datetime is in a different timezone, you can set the timezone and it will be saved as UTC correctly. # setting timezone for now()
datetime.datetime.now(tz=some_time_zone)
# add timezone to datetime with no tz info
dt.replace(tzinfo=some_time_zone)
# datetime is in utc
dt.replace(tzinfo=datetime.timezone.utc) This fix will require the library dateutils. There is no other way to get local timezone without another library. You can maybe add an option to change the local timezone to something different from the client. |
Hi, @Thordin. This fix looks pretty good. But ClickHouse server has it's own timezone: I think we need to use server's timezone instead of using UTC What do you think? |
I am not an expert in clickhouse, but I think the server stores the time in UTC no matter what timezone the server has. I think the server timezone is only for the client to display and convert to UTC. I am not sure, maybe you can double check. My clickhouse server timezone is not GMT.
But when I insert a timezone in clickhouse-client by doing this... and get it with clickhouse-driver, it is UTC.
So I don't think you should store the datetime in the server's timezone. But you should double check, maybe I made a mistake. But for me, my clickhouse server stores data in UTC even when the timezone is set to local, at least when clickhouse-driver reads it. That's why v-v-vishnevskiy discovered this problem. |
Hi @xzkostyan ,
I think it will help. |
Hi. I'm working on this issue. Fix will be ready soon. |
Hi, Here is commit with timezone support: f645ead. You can test it on latest master: pip install git+https://github.com/mymarilyn/clickhouse-driver@master#egg=clickhouse-driver |
Hi, |
Version 0.0.11 is released. It contains this issue fix. |
Hi!
After insert datetime.datetime(2018, 1, 19, 10) through this driver I see '2018-01-19 13:00:00' value in table.
Timezone on my computer and clickhouse server is Moskow.
What I must do to see '2018-01-19 10:00:00' after insert?
The text was updated successfully, but these errors were encountered: