In MariaDB, POW()
is a built-in function that returns the value of its first argument raised to the power of its second argument.
Syntax
The syntax goes like this:
POW(X,Y)
It returns X
raised to the power of Y
.
The POWER()
function is a synonym to POW()
, so it can also be done like this:
POWER(X,Y)
Example
Here’s an example to demonstrate:
SELECT POW(2, 3);
Result:
+-----------+ | POW(2, 3) | +-----------+ | 8 | +-----------+
Negative Values
Here are some examples that use negative values:
SELECT
POW(-2, 3),
POW(2, -3),
POW(-2, -3);
Result:
+------------+------------+-------------+ | POW(-2, 3) | POW(2, -3) | POW(-2, -3) | +------------+------------+-------------+ | -8 | 0.125 | -0.125 | +------------+------------+-------------+
Non-Numeric Arguments
Here’s an example of what happens when we provide non-numeric arguments:
SELECT POW('Homer', 'Symptom');
Result:
+-------------------------+ | POW('Homer', 'Symptom') | +-------------------------+ | 1 | +-------------------------+ 1 row in set, 2 warnings (0.000 sec)
Let’s see the warning:
SHOW WARNINGS;
Result:
+---------+------+---------------------------------------------+ | Level | Code | Message | +---------+------+---------------------------------------------+ | Warning | 1292 | Truncated incorrect DOUBLE value: 'Homer' | | Warning | 1292 | Truncated incorrect DOUBLE value: 'Symptom' | +---------+------+---------------------------------------------+
Null Arguments
POW()
returns null
if any argument is null
:
SELECT
POW(2, null),
POW(null, 3),
POW(null, null);
Result:
+--------------+--------------+-----------------+ | POW(2, null) | POW(null, 3) | POW(null, null) | +--------------+--------------+-----------------+ | NULL | NULL | NULL | +--------------+--------------+-----------------+
Missing Arguments
Calling POW()
with the wrong number of arguments, or without any arguments results in an error:
SELECT POW();
Result:
ERROR 1582 (42000): Incorrect parameter count in the call to native function 'POW'
And:
SELECT POW(10, 2, 3);
Result:
ERROR 1582 (42000): Incorrect parameter count in the call to native function 'POW'