> This page location: Math Functions > SQRT
> Full Neon documentation index: https://neon.com/docs/llms.txt

# PostgreSQL SQRT() Function

**Summary**: in this tutorial, you will learn how to use the PostgreSQL `SQRT()` function to calculate the square root of a number.

## Introduction to the PostgreSQL SQRT() function

The `SQRT()` function is a powerful mathematical function that allows you to calculate the square root of a number.

Here's the basic syntax of the `SQRT()` function:

```sql
SQRT(number)
```

In this syntax, the `number` is a numeric value for which you want to calculate the square root

The `SQRT()` function returns the square root of the input `number`.

## PostgreSQL SQRT() function examples

Let's take some examples of using the `SQRT()` function.

### 1) Basic SQRT() function example

The following example uses the `SQRT()` function to return the square root of 25:

```sql
SELECT SQRT(25) AS result;
```

Output:

```text
 result
--------
      5
(1 row)
```

The query returns the square root of 25, which is 5.

### 2) Using PostgreSQL SQRT() function to calculate distance

Suppose you have a table called `coordinates` that consists of columns `x` and `y` representing the coordinates of points in two-dimensional space:

```sql
-- Create coordinates table
CREATE TABLE coordinates (
    id SERIAL PRIMARY KEY,
    x NUMERIC,
    y NUMERIC
);

-- Insert sample data
INSERT INTO coordinates (x, y) VALUES
    (3, 4),
    (-2, 5),
    (0, 0),
    (8, -6),
    (-1.5, 2.5)
RETURNING *;
```

Output:

```text
 id |  x   |  y
----+------+-----
  1 |    3 |   4
  2 |   -2 |   5
  3 |    0 |   0
  4 |    8 |  -6
  5 | -1.5 | 2.5
(5 rows)
```

The following query uses the `SQRT()` function to calculate the distance of each point from the origin (0,0):

```sql
SELECT SQRT(x * x + y * y) AS distance_from_origin
FROM coordinates;
```

Output:

```text
 distance_from_origin
----------------------
    5.000000000000000
    5.385164807134504
    0.000000000000000
   10.000000000000000
    2.915475947422650
(5 rows)
```

## Summary

- Use the PostgreSQL `SQRT()` function to calculate the square root of a number.

---

## Related docs (Math Functions)

- [ABS](https://neon.com/postgresql/postgresql-math-functions/postgresql-abs)
- [CBRT](https://neon.com/postgresql/postgresql-math-functions/postgresql-cbrt)
- [CEIL](https://neon.com/postgresql/postgresql-math-functions/postgresql-ceil)
- [DEGREES](https://neon.com/postgresql/postgresql-math-functions/postgresql-degrees)
- [DIV](https://neon.com/postgresql/postgresql-math-functions/postgresql-div)
- [EXP](https://neon.com/postgresql/postgresql-math-functions/postgresql-exp)
- [FACTORIAL](https://neon.com/postgresql/postgresql-math-functions/postgresql-factorial)
- [FLOOR](https://neon.com/postgresql/postgresql-math-functions/postgresql-floor)
- [GCD](https://neon.com/postgresql/postgresql-math-functions/postgresql-gcd)
- [LCM](https://neon.com/postgresql/postgresql-math-functions/postgresql-lcm)
- [LN](https://neon.com/postgresql/postgresql-math-functions/postgresql-ln)
- [LOG](https://neon.com/postgresql/postgresql-math-functions/postgresql-log)
- [MOD](https://neon.com/postgresql/postgresql-math-functions/postgresql-mod)
- [MIN_SCALE](https://neon.com/postgresql/postgresql-math-functions/postgresql-min_scale)
- [PI](https://neon.com/postgresql/postgresql-math-functions/postgresql-pi-function)
- [POWER](https://neon.com/postgresql/postgresql-math-functions/postgresql-power)
- [RADIANS](https://neon.com/postgresql/postgresql-math-functions/postgresql-radians)
- [RANDOM](https://neon.com/postgresql/postgresql-math-functions/postgresql-random)
- [ROUND](https://neon.com/postgresql/postgresql-math-functions/postgresql-round)
- [SCALE](https://neon.com/postgresql/postgresql-math-functions/postgresql-scale)
- [SIGN](https://neon.com/postgresql/postgresql-math-functions/postgresql-sign)
- [TRIM_SCALE](https://neon.com/postgresql/postgresql-math-functions/postgresql-trim_scale)
- [TRUNC](https://neon.com/postgresql/postgresql-math-functions/postgresql-trunc)
- [WIDTH_BUCKET](https://neon.com/postgresql/postgresql-math-functions/postgresql-width_bucket)
