In order to get square root of column in PostgreSQL we use SQRT() function. SQRT() function in PostgreSQL gets the square root of the column. Let’s see how to
- Get square root in PostgreSQL
- Create the column which extracts the square root from another column
With an example for both
Syntax:
SQRT(numeric_expression)
numeric_expression: The number for which you want to calculate the square root. This expression must be non-negative.
Get Square root in Postgresql:
SQRT() function in posgresql gets the square root value
SELECT SQRT(9) AS square_root;
So the square root will be
Get Square root of column in PostgreSQL table:
We use table student_details
SELECT *, ROUND(CAST(SQRT(gradscore) as numeric),2) AS squareroot_gradscore FROM student_detail;
We have created a column and stored squareroot of gradscore column.
So the resultant table will be
Output: