power(numeric, numeric) — Raise a number to a power
Last updated: 2026-11-04
power(numeric, numeric) — Raise a number to a power
power(a, b) returns a raised to the b-th power, which comes up for exponential growth, compound interest and geometric scaling. The result type follows the first argument, so numeric gives an exact decimal result; a negative base with a fractional exponent raises an error because the result would be complex.
| Kind | function |
|---|---|
| Example Language | SQL |
📝 Syntax
power(dp numeric, exponent numeric) → numeric
⚙️ Parameters
| dp numeric | The base. Type numeric. |
|---|---|
| exponent numeric | The exponent. Type numeric. |
Returns:numeric — the computed power.
▶ Example
Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.
Output:
id | label | result
----+-------------+--------------------
1 | square | 16.000000000000000
2 | cube | 27.000000000000000
3 | square-root | 3.0000000000000000
(3 rows)
📌 Key Points
- numeric returns an exact decimal value, but the scale can be long, so round() it for readability.
- power(9, 0.5) returns 3.0000000000000000 on numeric rather than the integer 3.
- A negative base with a fractional exponent raises "a negative number raised to a non-integer power yields a complex result".
💡 Related Cases
More case studies coming soon.
📚 Related Reference
❓ FAQ
QHow does power() differ from the ^ operator?
AThey are equivalent — ^ is the operator form of power(). The real difference is the type: power(9, 0.5) on numeric gives an exact decimal, while sqrt() is the dedicated square-root function.