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

# PostgreSQL CBRT() Function

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

## Introduction to the PostgreSQL CBRT() function

A cube root number is a number that when you multiply itself twice, you'll get the cube number. For example, 2 is a cube root number of 8 because when you multiply the number 2 by itself three times, you'll get the number 8:

```sql
2 * 2 * 2 = 8
```

In PostgreSQL, the `CBRT()` is a math function that returns the cube root of a number.

Here's the syntax of the `CBRT()` function:

```sql
CBRT(n)
```

In this syntax:

- `n` is the number that you want to calculate the cube root. `n` can be a literal number, an expression, or a table column.

The `CBRT()` function returns the cube root of a number n with the double precision type. If `n` is `NULL`, the `CBRT()` function returns `NULL`.

If `n` is a string, the `CBRT()` function will attempt to convert it to a number before calculating the cube root. If the conversion fails, it raises an error.

## PostgreSQL CBRT() function examples

Let's explore some examples of using the `CBRT()` function.

### 1) Basic PostgreSQL CBRT() function example

The following example uses the `CBRT()` function to calculate the cube root of 27:

```sql
SELECT CBRT(27) result;
```

Output:

```text
 result
--------
      3
```

It returns 3 because 3* 3 *3 = 27.

### 2) Using CBRT() function with a negative number

The following example uses the `CBRT()` function to find the cube root of -27:

```sql
SELECT CBRT(-27) result;
```

Output:

```text
 result
--------
     -3
```

The result is -3 because -3 * -3 * -3 is -27. Please note that the cube root of a negative number is always negative.

### 3) Using CBRT() function with numeric strings

The following example uses the `CBRT()` function with a numeric string:

```sql
SELECT CBRT('125') result;
```

Output:

```text
 result
--------
      5
```

In this example, the `CBRT()` function converts the text '125' to the number 125 and calculates the cube root.

### 4) Using the CBRT() function with table data

First, [create a table](../postgresql-tutorial/postgresql-create-table) called `cube_volumes` that stores the volumes of cubes:

```sql
CREATE TABLE cube_volumes(
    id INT GENERATED ALWAYS AS IDENTITY,
    volume DEC(19,2),
    PRIMARY KEY(id)
);
```

Second, [insert rows](../postgresql-tutorial/postgresql-insert-multiple-rows) into the `cube_volumes` table:

```sql
INSERT INTO
  cube_volumes (volume)
VALUES
  (8),
  (125),
  (NULL),
  (0)
RETURNING *;
```

Output:

```text
 id | volume
----+--------
  1 |   8.00
  2 | 125.00
  3 |   null
  4 |   0.00
(4 rows)
```

Third, calculate the side lengths of cubes using the `CBRT()` function:

```sql
SELECT
  id,
  volume,
  CBRT (volume) side_length
FROM
  cube_volumes;
```

Output:

```text
 id | volume | side_length
----+--------+-------------
  1 |   8.00 |           2
  2 | 125.00 |           5
  3 |   null |        null
  4 |   0.00 |           0
(4 rows)
```

## Summary

- Use the `CBRT()` function to calculate the cube root of a number.

---

## Related docs (Math Functions)

- [ABS](https://neon.com/postgresql/postgresql-math-functions/postgresql-abs)
- [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)
- [SQRT](https://neon.com/postgresql/postgresql-math-functions/postgresql-sqrt)
- [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)
