-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
sql: interval division with float rounds differently from Python & PostgreSQL #66118
Comments
Hello, I am Blathers. I am here to help you get the issue triaged. Hoot - a bug! Though bugs are the bane of my existence, rest assured the wretched thing will get the best of care here. I have CC'd a few people who may be able to assist you:
If we have not gotten back to your issue within a few business days, you can try the following:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
I made a minimal reproduction of this discrepancy. Looks like Cockroach is somehow keeping track of more precision than Postgres, because Cockroach decides to round (0.000001 / 2) up to 0.000001, whereas Postgres treats it more like integer division, rounding (0.000001 / 2) down to 0. Postgres: postgres=# SELECT (INTERVAL '0.000001' / 2);
?column?
----------
00:00:00
(1 row) Cockroach: root@:26257/defaultdb> SELECT (INTERVAL '0.000001' / 2);
?column?
-------------------
00:00:00.000001
(1 row)
Time: 0ms total (execution 0ms / network 0ms) |
Thanks @kernfeld-cockroach! cc @otan does anything come to mind immediately from when you last looked at INTERVAL? |
ah yes, it's because we use cockroach/pkg/util/duration/duration.go Line 251 in 3f04bd5
|
on closer observation, the round down behaviour only exists for division.
|
@otan I am new here. Can I try this issue? I think maybe I can try this issue by following the instructions listed by you. |
Go for it! |
@otan I have ran the command |
this means the table "test1" does not exist. did you create something that references test1? what code did you add to the file? |
… & PostgreSQL Before this commit, the nanos will be rounded in `MakeDuration`. This commit round down nanos before `rounded` is called in the div of duration. Fixes cockroachdb#66118 Release note: None
I have fixed the problem I mentioned. I have also filed a PR for this issue. @otan PTAL |
…eSQL Before this commit, the nanos will be rounded in `MakeDuration`. This commit round down nanos before `rounded` is called in the div of duration. Fixes cockroachdb#66118 Release note (bug fix): Fixed a bug with PostgreSQL compatibility where dividing an interval by a number would round to the nearest Microsecond instead of always rounding down.
66345: util: Fix interval division with float rounds differently from Python & PostgreSQL r=otan a=TszKitLo40 Before this commit, the nanos will be rounded in `MakeDuration`. This commit round down nanos before `rounded` is called in the div of duration. Fixes #66118 Release note: None Co-authored-by: Zijie Lu <[email protected]>
…eSQL Before this commit, the nanos will be rounded in `MakeDuration`. This commit round down nanos before `rounded` is called in the div of duration. Fixes cockroachdb#66118 Release note (bug fix): Fixed a bug with PostgreSQL compatibility where dividing an interval by a number would round to the nearest Microsecond instead of always rounding down.
…eSQL Before this commit, the nanos will be rounded in `MakeDuration`. This commit round down nanos before `rounded` is called in the div of duration. Fixes cockroachdb#66118 Release note (bug fix): Fixed a bug with PostgreSQL compatibility where dividing an interval by a number would round to the nearest Microsecond instead of always rounding down.
…eSQL Before this commit, the nanos will be rounded in `MakeDuration`. This commit round down nanos before `rounded` is called in the div of duration. Fixes cockroachdb#66118 Release note (bug fix): Fixed a bug with PostgreSQL compatibility where dividing an interval by a number would round to the nearest Microsecond instead of always rounding down.
66345: util: Fix interval division with float rounds differently from PostgreSQL r=otan a=TszKitLo40 Before this commit, the nanos will be rounded in `MakeDuration`. This commit round down nanos before `rounded` is called in the div of duration. Fixes #66118 Release note (bug fix): Fixed a bug with PostgreSQL compatibility where dividing an interval by a number would round to the nearest Microsecond instead of always rounding down. Co-authored-by: Zijie Lu <[email protected]>
@TszKitLo40 thanks for the quick fix!! |
see #66118 (comment) for solution
Describe the problem
Interval division with a float rounds differently from Python & PostgreSQL.
To Reproduce
Expected behavior
Expected result of SELECT query:
00:00:00.079062
.Environment:
Additional context
A Django test fails:
The text was updated successfully, but these errors were encountered: