You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The specification leaves the implementor guessing as to the semantics of numeric expression, and the type assigned to numeric literals.
§4.6.17.1 lists the arithmetic operators and says:
Arithmetic operations use numeric promotion.
§4.6.1 says:
Exact numeric literals support the use of Java integer literal syntax as well as SQL exact numeric literal syntax.
Approximate literals support the use Java floating point literal syntax as well as SQL approximate numeric literal syntax.
But this leaves a lot unspecified. For example, what type does the following query return:
select 1.23 from Entity
Double? Float? BigDecimal?
Worse, what value does this query return:
select 1/2 from Entity
That is, does "use numeric promotion" mean that this is an integer division or is it promoted to float? Or to double? (Note that different SQL databases disagree on this question.)
I propose that we nail this stuff down by simply saying that:
the semantics of numeric literals and arithmetic expressions are the same as in Java (so that 1/2 is integer division),
with the additional rule that (a) integral types may be widened to BigInteger or BigDecimal, (b) BigInteger may be widened to BigDecimal, and (c) floating point types may be widened to BigDecimal.
Actually, I'm not completely clear on whether FP types should be widened to BigDecimal, but I'm thinking they should be, simply because that's something every SQL database allows.
The text was updated successfully, but these errors were encountered:
gavinking
added a commit
to gavinking/persistence
that referenced
this issue
Aug 7, 2023
The specification leaves the implementor guessing as to the semantics of numeric expression, and the type assigned to numeric literals.
§4.6.17.1 lists the arithmetic operators and says:
§4.6.1 says:
But this leaves a lot unspecified. For example, what type does the following query return:
Double
?Float
?BigDecimal
?Worse, what value does this query return:
That is, does "use numeric promotion" mean that this is an integer division or is it promoted to float? Or to double? (Note that different SQL databases disagree on this question.)
I propose that we nail this stuff down by simply saying that:
1/2
is integer division),BigInteger
orBigDecimal
, (b)BigInteger
may be widened toBigDecimal
, and (c) floating point types may be widened toBigDecimal
.Actually, I'm not completely clear on whether FP types should be widened to
BigDecimal
, but I'm thinking they should be, simply because that's something every SQL database allows.The text was updated successfully, but these errors were encountered: