Arithmetic exponentiation operator ^
Last updated: 2026-11-04
Arithmetic exponentiation operator ^
The exponentiation operator ^ raises the left operand to the power of the right operand and is equivalent to the power() function. It accepts fractional exponents, so 9 ^ 0.5 is 3. Integer operands take the double precision path while numeric operands keep exact decimal semantics. A NULL operand yields a NULL result.
| Kind | operator |
|---|---|
| Example Language | SQL |
📝 Syntax
a ^ b
Precedence: `^` binds tighter than `* / %` but looser than unary `+ -` (hence `-2^2` is 4). It is left-associative at its own level, so `2 ^ 3 ^ 2` is (2^3)^2 = 64, not 2^(3^2) = 512. Parenthesise `2 ^ (3 ^ 2)` for right-associative grouping.
⚙️ Parameters
| a | The base; if NULL the result is NULL. |
|---|---|
| b | The exponent, integer or fractional; if NULL the result is NULL. |
Returns:double precision for integer operands or numeric for numeric operands; NULL if either operand is NULL.
▶ 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:
SELECT id, base ^ exponent AS power, power(base, exponent) AS power_fn FROM t_pow ORDER BY id
id | power | power_fn
---+--------------------+-------------------
1 | 1024.0000000000000 | 1024.0000000000000
2 | 3.0000000000000000 | 3.0000000000000000
3 | NULL | NULL
(3 rows)
SELECT base ^ exponent IS NULL AS null_is_absent FROM t_pow WHERE id = 3
null_is_absent
--------------
true
(1 row)
📌 Key Points
- NULL propagation: the result is NULL if the base or the exponent is NULL.
- ^ and power() are fully equivalent — pick whichever reads better.
- Left-associative at the same level: 2 ^ 3 ^ 2 is 64, the opposite of the right-associative convention in many languages.
💡 Related Cases
More case studies coming soon.
📚 Related Reference
❓ FAQ
QWhat is 2 ^ 3 ^ 2?
A64. PostgreSQL evaluates ^ left-associatively: 2^3 is 8, then 8^2 is 64. Write `2 ^ (3 ^ 2)` for 512.