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
Syntax
sqrt(x) | cbrt(x)
Parameters
| Parameter | Description |
|---|---|
x |
A number (integer, numeric or double precision). |
Return value
double precision or numeric.
Examples
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.
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
SQRT()· SQLite
Related
POWER()· Raise a number to a power, so power(2, 10) is 1024. pow() is another name for the same function.- SQL Aggregate Functions · tutorial