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

Datetime precision issue #95

Closed
romamur opened this issue Jul 20, 2023 · 6 comments
Closed

Datetime precision issue #95

romamur opened this issue Jul 20, 2023 · 6 comments

Comments

@romamur
Copy link

romamur commented Jul 20, 2023

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.

@romamur
Copy link
Author

romamur commented Jul 22, 2023

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)

@PNixx
Copy link
Owner

PNixx commented Jul 22, 2023

@romamur
Copy link
Author

romamur commented Jul 23, 2023

image

@PNixx
Copy link
Owner

PNixx commented Jul 24, 2023

I checked, it not working with Rails 7, working with only Rails 6

@PNixx PNixx reopened this Jul 24, 2023
@PNixx
Copy link
Owner

PNixx commented Jul 24, 2023

Please, check from rails_7 branch

@romamur
Copy link
Author

romamur commented Jul 26, 2023

Worked on rails_7 branch 🎉
image

@PNixx PNixx closed this as completed Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants