PostgreSQL Tutorial PostgreSQL Advanced PostgreSQL Database Account Management PostgreSQL References
PostgreSQL Tutorial PostgreSQL Advanced PostgreSQL Database Account Management PostgreSQL References

PostgreSQL SQRT() Function



The PostgreSQL SQRT() function returns the square root of a given number. If the argument is a negative value, an error is returned.

Syntax

SQRT(number)

Parameters

number Required. Specify the number. Must be a non-negative value.

Return Value

Returns the square root of a given number.

Example 1:

The example below shows the usage of SQRT() function.

SELECT SQRT(2);
Result: 1.4142135623730951

SELECT SQRT(3);
Result: 1.7320508075688772

SELECT SQRT(10);
Result: 3.1622776601683795

SELECT SQRT(50);
Result: 7.0710678118654755

SELECT SQRT(100);
Result: 10

Example 2:

Consider a database table called Sample with the following records:

Datax
Data 10.5
Data 21
Data 35
Data 410
Data 550

The statement given below can be used to calculate the square root of column x.

SELECT *, SQRT(x) AS SQRT_Value FROM Sample;

This will produce the result as shown below:

DataxSQRT_Value
Data 10.50.7071067811865476
Data 211
Data 352.23606797749979
Data 4103.1622776601683795
Data 5507.0710678118654755

❮ PostgreSQL Functions