Search code examples
sqlamazon-athenaprestotrino

Athena gets order of operations wrong


What is Athena doing here?

select
(10.0*12+10/10000)

It returns a value of 120.0

I know it's not rounding off because the "10" and the "12" in my code are small fractions < 0.01.


Solution

  • You got struck by another case of integer division. 10/10000 is calculated before the sum and type of 10/10000 result is determined by the types taking part in the division, hence select typeof(10/10000) is integer, change one of operands to be double (potentially with correct precision):

    select (10.0*12 + 10.000/10000);
    

    Output:

      _col0  
    ---------
     120.001