NumbersSQL standard

SQRT

Takes the square root of a number.

Syntax

SQRT(<number>)
CBRT(<number>)

SQRT(16) gives 4. For an integer the result is double precision, and for numeric — numeric. The cube root is CBRT.

Square and cube roots
SELECT SQRT(16) AS square_root,
SQRT(2) AS irrational,
CBRT(27) AS cube_root;
square_rootirrationalcube_root
41.41421356237309513
The distance between two points
SELECT SQRT(POWER(3, 2) + POWER(4, 2)) AS distance;
distance
5

Watch out

The root of a negative number is an error: SQRT(-4) says cannot take square root of a negative number.

For an integer argument the result is double precision, with possible rounding errors: SQRT(2) is 1.4142135623730951. For exact calculations pass a numeric: SQRT(2::numeric).

|/ is the same root as an operator: |/ 16 gives 4. But few people will recognise it in code, so SQRT is clearer.

Related functions