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: investigate using arbitrary precision constants #1795

Closed
petermattis opened this issue Jul 24, 2015 · 2 comments
Closed

sql: investigate using arbitrary precision constants #1795

petermattis opened this issue Jul 24, 2015 · 2 comments
Assignees
Labels
A-sql-semantics C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)
Milestone

Comments

@petermattis
Copy link
Collaborator

Currently, SELECT 1 + 1.0 does not work because 1 is parsed as an int and 1.0 is parsed as a float and we disallow implicit conversions between int and float. An alternative is to borrow from the Go playbook and support arbitrary precision constants and allow implicit conversions of these constants and expressions involving them when the conversion does not lose precision. This would be quite a bit more involved than the current system, making this issue low priority. Can draw inspiration and ideas from https://godoc.org/golang.org/x/tools/go/exact.

@petermattis petermattis added this to the 1.0 milestone Aug 14, 2015
@tbg tbg added the SQL label Aug 15, 2015
@rlowe
Copy link

rlowe commented Feb 3, 2016

While SQL:2011 basically leaves much of this as an implementation detail ...

"Every number has a precision (number of digits), and exact numeric types also have a scale (digits after the radix point). Arithmetic operations may be performed on operands of different or the same numeric type, and the result is of a numeric type that depends only on the numeric type of the operands. If the result cannot be represented exactly in the result type, then whether it is rounded or truncated is implementation-defined. An exception condition is raised if the result is outside the range of numeric values of the result type, or if the arithmetic operation is not defined for the operands."

Users of, operators of, and software powered by relational data stores really expect arithmetic functions like this to just work. For example:

mysql> SELECT 1 + 1.0;
+---------+
| 1 + 1.0 |
+---------+
|     2.0 |
+---------+
1 row in set (0.00 sec)
postgres=# SELECT 1 + 1.0 AS math;
 math 
------
  2.0
(1 row)

UPDATE: Formatting is hard

knz added a commit to knz/cockroach that referenced this issue Feb 7, 2016
@petermattis petermattis added C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) and removed SQL labels Feb 13, 2016
@petermattis petermattis modified the milestones: 1.0, Q2, Beta Apr 6, 2016
@nvanbenschoten
Copy link
Member

Implemented in #6358.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-semantics C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)
Projects
None yet
Development

No branches or pull requests

6 participants