How sqrt() Works in PostgreSQL

In PostgreSQL, the sqrt() function returns the square root of its argument.

The square root of a number x is the number y such that y2 = x.

Syntax

The syntax is quite simple:

sqrt(dp or numeric)

Where dp is a double precision value.

Example 1

Here’s an example to demonstrate its usage.

SELECT sqrt(64);

Result:

8

Example 2

You can also pass expressions such as the following.

SELECT sqrt(60 + 4);

Result:

8

Example 3

Here’s another quick example that demonstrates how it works.

SELECT 
  (4 * 4),
  sqrt(4 * 4),
  sqrt(16);

Result:

 ?column? | sqrt | sqrt
----------+------+------
       16 |    4 |    4

Example 4

Here’s one that results in fractional seconds being returned.

SELECT sqrt(50);

Result:

7.0710678118654755

Example 5

Here’s one where I include fractional seconds in the argument.

SELECT sqrt(0.123456);

Result:

0.35136306009596399