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

# PostgreSQL POWER() Function

**Info:** The POWER() function works the same on any standard PostgreSQL deployment, so what you learn here carries over wherever you run Postgres. If you're an enterprise looking for managed cloud Postgres built for the AI era, [Lakebase](https://www.databricks.com/product/lakebase) delivers high performance, strong security, and native integration with the Lakehouse. If you're a developer or startup who needs to ship and scale quickly, [Neon](https://neon.com) is the Postgres platform built for that pace.

**Summary**: in this tutorial, you will learn how to use the PostgreSQL `POWER()` function to raise a number to a specific power.

## Introduction to PostgreSQL POWER() function

The `POWER()` function allows you to raise a number to a specific power. Here's the basic syntax of the `POWER()` function:

```sql
POWER(base, exponent)
```

In this syntax:

- `base`: This is the base number
- `exponent`: This is the exponent to which you want to raise the base number.

The `POWER()` function returns a numeric value representing the result of raising the base number to a specified exponent. It returns `NULL` if either `base` or `exponent` is `NULL`.

## PostgreSQL POWER() function examples

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

### 1) Basic POWER() function examples

The following example uses the `POWER()` function to raise the number to the power of 3:

```sql
SELECT POWER(2,3) result;
```

Output:

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

Similarly, you can use the `POWER()` function with decimal values:

```sql
SELECT POWER(2.5, 2);
```

Output:

```text
       power
--------------------
 6.2500000000000000
(1 row)
```

### 2) Using the POWER() function with negative exponent

The following example uses the `POWER()` function with a negative exponent:

```sql
SELECT POWER(10, -2);
```

Output:

```text
 power
-------
  0.01
(1 row)
```

In this example, we raise 10 to the power of -2 resulting in `0.01`.

### 3) Using the POWER() function with a fractional exponent

The following example uses the `POWER()` function to raise the number 2 to the power of `1.5`:

```sql
SELECT POWER(2, 1.5);
```

Output:

```text
       power
--------------------
 2.8284271247461901
(1 row)
```

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

We'll use the `POWER()` function to calculate [compound interest](https://en.wikipedia.org/wiki/Compound_interest).

First, [create a table](../postgresql-tutorial/postgresql-create-table) called `investments` to store the investment data:

```sql
CREATE TABLE investments (
    id SERIAL PRIMARY KEY,
    investment_amount NUMERIC NOT NULL,
    annual_interest_rate NUMERIC NOT NULL,
    years INT NOT NULL
);
```

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

```sql
INSERT INTO investments (investment_amount, annual_interest_rate, years)
VALUES
    (1000, 5, 1),
    (2000, 7, 3),
    (5000, 4.5, 5)
RETURNING *;
```

Output:

```text
 id | investment_amount | annual_interest_rate | years
----+-------------------+----------------------+-------
  1 |              1000 |                    5 |     1
  2 |              2000 |                    7 |     3
  3 |              5000 |                  4.5 |     5
(3 rows)
```

Third, calculate the compound interest of each investment in the `investments` table:

```sql
SELECT
    investment_amount,
    annual_interest_rate,
    years,
    ROUND(investment_amount * POWER(1 + (annual_interest_rate / 100), years), 2) AS future_value
FROM
    investments;
```

Output:

```text
 investment_amount | annual_interest_rate | years | future_value
-------------------+----------------------+-------+--------------
              1000 |                    5 |     1 |      1050.00
              2000 |                    7 |     3 |      2450.09
              5000 |                  4.5 |     5 |      6230.91
(3 rows)
```

The query returns the initial investment details along with the calculated future value for each investment.

To calculate the compound interest of each investment:

- Calculate the interest rate using the `POWER()` function.
- Use the [`ROUND()`](https://neon.com/postgresql/math-functions/postgresql-round) function to round the future value to two decimal places.

## Summary

- Use the PostgreSQL `POWER()` function to raise a number to a specific power.

---

## Related docs (Math Functions)

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