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

sql: fractional years in intervals should be truncated at months #55226

Closed
jordanlewis opened this issue Oct 5, 2020 · 1 comment · Fixed by #55230
Closed

sql: fractional years in intervals should be truncated at months #55226

jordanlewis opened this issue Oct 5, 2020 · 1 comment · Fixed by #55230
Labels
A-sql-pgcompat Semantic compatibility with PostgreSQL

Comments

@jordanlewis
Copy link
Member

In Postgres, it appears that specifying an interval with a fractional year quantity returns an interval whose precision is at best "months":

jordan=# select '1 year'::interval;
 interval
----------
 1 year
(1 row)

jordan=# select '1.5 year'::interval;
   interval
---------------
 1 year 6 mons
(1 row)

jordan=# select '1.99 year'::interval;
    interval
----------------
 1 year 11 mons
(1 row)

jordan=# select '1.99999 year'::interval;
    interval
----------------
 1 year 11 mons
(1 row)

In Cockroach, we do not truncate the precision, giving a "more accurate looking" but incompatible-with-Postgres response:

root@:26257/defaultdb> select '1 year'::interval;
  interval
------------
  1 year
(1 row)

Time: 0ms total (execution 0ms / network 0ms)

root@:26257/defaultdb> select '1.5 year'::interval;
    interval
-----------------
  1 year 6 mons
(1 row)

Time: 0ms total (execution 0ms / network 0ms)

root@:26257/defaultdb> select '1.99 year'::interval;
             interval
-----------------------------------
  1 year 11 mons 26 days 09:36:00
(1 row)

Time: 0ms total (execution 0ms / network 0ms)

root@:26257/defaultdb> select '1.99999 year'::interval;
               interval
--------------------------------------
  1 year 11 mons 29 days 23:54:48.96
(1 row)

Time: 0ms total (execution 0ms / network 0ms)

In the latter two cases, I guess we need to not even store the "extra precision" parts of the interval.

@jordanlewis jordanlewis added the A-sql-pgcompat Semantic compatibility with PostgreSQL label Oct 5, 2020
@blathers-crl
Copy link

blathers-crl bot commented Oct 5, 2020

Hi @jordanlewis, please add a C-ategory label to your issue. Check out the label system docs.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-pgcompat Semantic compatibility with PostgreSQL
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant