Raised to the power n in PostgreSQL – Power() Function

In order to find raised to the power n in PostgreSQL we use POWER() function. This function is useful for mathematical calculations where you need to exponentiate values. POWER() function in PostgreSQL gets value raised to the power n. Let’s see how to

  • Get value raised to the power n in PostgreSQL
  • Create the column which extracts the raised power of another column

With an example for both

Raised to the power n in Postgresql – Power() Function 1

 

Syntax:

POWER(base, exponent)

  • base: The number to be raised.
  • exponent: The power to which the base number is raised.

 

Get value raised to the power n in PostgreSQL:

POWER() function in PostgreSQL gets the value raised to the power

 

SELECT POWER(3,2) AS square

Select POWER(3,3) AS cube

So, the raised power 2 will be

Raised to the power n in Postgresql – Power() Function 2

Raised power 3 will be

Raised to the power n in Postgresql – Power() Function 3

 

 

Get raised power of column in PostgreSQL table:

We use table student_details

Raised to the power n in Postgresql – Power() Function 4

 

SELECT *,POWER(gradscore,4) AS power4_gradscore FROM student_detail;

We have created a column and stored power four of gradscore column.

So the resultant table will be

Raised to the power n in Postgresql – Power() Function 5

 

 

Author

  • Sridhar Venkatachalam

    With close to 10 years on Experience in data science and machine learning Have extensively worked on programming languages like R, Python (Pandas), SAS, Pyspark.

    View all posts