// math reference

SQL POWER function

Raises a base to an exponent: POWER(2, 10) is 1024. On SQL Server the result takes the base's type, so integer bases can overflow or lose fractions.

Categoria
Math
Returns
float or numeric
In this category
6 of 82

Sintaxe

POWER(base, exponent)
POW(base, exponent)  -- MySQL, PostgreSQL, SQLite
base ^ exponent  -- PostgreSQL

Each block is a separate form. The support table and the examples show which engine takes which.

Suporte a mecanismos

MotorSupportNotas
SQL Server Sim Supported under this name.
PostgreSQL Sim POWER, POW and the ^ operator
MySQL Sim POWER and POW
SQLite Sim POWER and POW, math functions from SQLite 3.35+
Oracle Sim Supported under this name.

Exemplos

Any engine

SELECT POWER(2, 10) AS kilo;  -- 1024

Any engine

SELECT principal * POWER(1.05, years) AS compound
FROM deposits;

Bom saber

  • SQL Server returns the base's type: POWER(2, 10) is int, POWER(2, 31) overflows, and POWER(2, -1) is 0. Cast the base: POWER(CAST(2 AS float), 31). PostgreSQL, MySQL and SQLite return double precision for integer inputs.
  • PostgreSQL's ^ operator is exponentiation, but on SQL Server and MySQL ^ is bitwise XOR: 2 ^ 3 is 8 on PostgreSQL and 1 on the other two.
  • A negative base with a fractional exponent has no real result: SQLite returns NULL, while SQL Server, PostgreSQL, MySQL and Oracle raise an error for POWER(-8, 0.5).

Questions about POWER / POW

What is the difference between POWER and POW?

Nothing. PostgreSQL, MySQL and SQLite accept both spellings; SQL Server and Oracle only have POWER.

Why does my POWER overflow?

On SQL Server the result has the base's type, so an int base overflows past 2,147,483,647. Cast the base: POWER(CAST(2 AS FLOAT), 100). Other engines already return double precision and only overflow near 1e308.

Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.

Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, SQLite, Oracle.

// fewer lookups

Functions your engine actually has

SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.