Datetime precision issue
romamur opened this issue · comments
I have gems clickhouse 0.1.10, clickhouse-activerecord 0.5.14, pg 1.4.6 and rails 7.0.4.3. ClickHouse server version 23.4.2.11, postgresql server 15.3.
My clickhouse table ddl:
create table default.tests
(
id UUID default generateUUIDv4(),
created_at DateTime64(6)
)
engine = MergeTree PARTITION BY toMonth(created_at) ORDER BY (id, created_at);
My model is Test. When i create record like:
Test.create
this produces sql query:
INSERT INTO tests (created_at) VALUES ('2023-06-10 08:41:57')
As you can see there is no precision (microseconds).
I can define rails time db format like this:
Time::DATE_FORMATS[:db] = '%Y-%m-%d %H:%M:%S.%6N'
then if i create record this will produce correct result:
INSERT INTO tests (created_at) VALUES ('2023-06-10 08:41:57.123123')
But this broke my PostgreSQL models sql queries! For example if i have model PgTest and if i create record like this:
PgTest.create
this will produce incorrect precision sql query in my postgresql database (duplicate precision):
INSERT INTO pg_tests (created_at) VALUES ('2023-06-10 08:41:57.123123.123123')
Setting Time db format in callback around_create - not an option for me.
Thanks for fix, but i have upgraded gem to 0.5.15 and this doesn't work :(
This produces sql query (there is no precision):
INSERT INTO tests (created_at) VALUES ('2023-06-10 08:41:57')
My Gemfile.lock:
clickhouse (0.1.10)
activesupport (>= 4.1.8)
bundler (>= 1.13.4)
erubis
faraday
launchy
pond
sinatra
thor
clickhouse-activerecord (0.5.15)
activerecord (>= 5.2)
bundler (>= 1.13.4)
I checked, it not working with Rails 7, working with only Rails 6
Please, check from rails_7 branch