In order to get square of column in PostgreSQL we use POWER() function. POWER() function in PostgreSQL gets the square of the column. Let’s see how to
- Get square value in PostgreSQL
- Create the column which extracts the square from another column
With an example for both
Syntax:
POWER(base, exponent)
- base: The number to be raised.
- exponent: The power to which the base number is raised.
Get Square in PostgreSQL:
POWER() function in PostgreSQL gets the square value
SELECT POWER(9,2) AS square;
So the square will be
Get Square of column in PostgreSQL table:
We use table student_details
SELECT *,POWER(gradscore,2) AS square_gradscore FROM student_detail;
We have created a column and stored square of gradscore column.
So the resultant table will be
Output: