PostgreSQL 18 reference · Math Functions

PostgreSQL SQRT() Function

Return the square root of a number, so sqrt(16) is 4. Negative input raises an error; cbrt() gives the cube root.

PostgreSQL 18

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

sqrt(x)  |  cbrt(x)

Parameters

ParameterDescription
x A number (integer, numeric or double precision).

Return value

double precision or numeric.

Examples

Roots
SELECT sqrt(16) AS a, sqrt(2::numeric) AS b, cbrt(64) AS cube_root;

Output

 a |         b         | cube_root
---+-------------------+-----------
 4 | 1.414213562373095 |         4
(1 row)

Run this on your computer — see “Get Started” for setup.

Distance between two points
SELECT sqrt(power(3, 2) + power(4, 2)) AS distance;

Output

 distance
----------
        5
(1 row)

Run this on your computer — see “Get Started” for setup.

In other languages

Was this page helpful?