1 Reply Latest reply on Sep 20, 2016 9:15 PM by Steven Hawkins

    How to calculate N root of X in query

    Raghu Kasukurthi Newbie

      Hi all,

      I want to calculate n√X (n root of X) in Teiid query.

       

      S= n√X  Where n= 1.89  & x is any input value

       

      Looking at  internet article I wrote below query Nth root of a number

       

      SELECT POWER(Convert(27,bigdecimal),Convert(1/1.89,bigdecimal))

      SELECT POWER(27,1/1.89)

       

      for both of the queries I am getting same error. Any thoughts how we can execute above formula ?

       

      cal.png

        • 1. Re: How to calculate N root of X in query
          Steven Hawkins Master

          The power function expects a double and 1/1.89 is bigdecimal.  Teiid treats the conversion of bigdecimal/numeric to double as potentially narrowing, which will depend on the exact value.  In this case unfortunately a cast is needed -

           

          SELECT POWER(27, cast(1/1.89 as double))

           

          You can see there is slight difference in the values:

           

          SELECT 1/cast(1.89 as double) = 1/1.89