Skip to main content

SQRT

Description

Returns the square root of a value, where the input value must be greater than or equal to 0.

Syntax

SQRT(<x>)

Parameters

ParameterDescription
<x>The value whose square root is to be calculated

Return Value

The square root of parameter x.

Special Cases

  • When x equals 0, returns 0
  • When x equals -0, returns -0
  • When x is less than 0, returns NULL
  • When x is NaN, returns NaN
  • When x is positive infinity, returns Infinity
  • When x is negative infinity, returns NULL
  • When x is NULL, returns NULL

Examples

select sqrt(9), sqrt(2);
+-------------------------+-------------------------+
| sqrt(cast(9 as DOUBLE)) | sqrt(cast(2 as DOUBLE)) |
+-------------------------+-------------------------+
| 3.0 | 1.4142135623730951 |
+-------------------------+-------------------------+
select sqrt(1.0);
+------------+
| sqrt(1.0) |
+------------+
| 1 |
+------------+
select sqrt(0.0);
+------------+
| sqrt(0.0) |
+------------+
| 0 |
+------------+
select sqrt(-0.0);
+-------------+
| sqrt(-0.0) |
+-------------+
| -0 |
+-------------+
select sqrt(-1.0);
+-------------+
| sqrt(-1.0) |
+-------------+
| NULL |
+-------------+
select sqrt(cast('nan' as double));
+---------------------------+
| sqrt(cast('nan' AS DOUBLE)) |
+---------------------------+
| NaN |
+---------------------------+
select sqrt(cast('inf' as double));
+---------------------------+
| sqrt(cast('inf' AS DOUBLE)) |
+---------------------------+
| Infinity |
+---------------------------+
select sqrt(cast('-inf' as double));
+----------------------------+
| sqrt(cast('-inf' AS DOUBLE)) |
+----------------------------+
| NULL |
+----------------------------+