jakartaee / persistence

https://jakartaee.github.io/persistence/
Other
191 stars 55 forks source link

nail down semantics of arithmetic expressions and numeric literals #423

Closed gavinking closed 12 months ago

gavinking commented 1 year ago

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:

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.

gavinking commented 12 months ago

Please see proposal https://github.com/jakartaee/persistence/pull/427, which clarifies section 4.6.1, and introduces proper support for BigInteger and BigDecimal literals.

does "use numeric promotion" mean that this is an integer division or is it promoted to float? Or to double?

Actually I guess this is sort of covered by section 4.8.6, though that section should be generalized to apply not only to the select clause.