MariaDB POWER() Explained

In MariaDB, POWER() is a synonym to POW(), which is 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:

POWER(X,Y)

It returns X raised to the power of Y.

As mentioned, POWER() is a synonym to POW(), so it can also be done like this:

POW(X,Y)

Example

Here’s an example to demonstrate:

SELECT POWER(2, 3);

Result:

+-------------+
| POWER(2, 3) |
+-------------+
|           8 |
+-------------+

Negative Values

Here are some examples that use negative values:

SELECT 
    POWER(-2, 3),
    POWER(2, -3),
    POWER(-2, -3);

Result:

+--------------+--------------+---------------+
| POWER(-2, 3) | POWER(2, -3) | POWER(-2, -3) |
+--------------+--------------+---------------+
|           -8 |        0.125 |        -0.125 |
+--------------+--------------+---------------+

Non-Numeric Arguments

Here’s an example of what happens when we provide non-numeric arguments:

SELECT POWER('Homer', 'Symptom');

Result:

+---------------------------+
| POWER('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

POWER() returns null if any argument is null:

SELECT 
    POWER(2, null),
    POWER(null, 3),
    POWER(null, null);

Result:

+----------------+----------------+-------------------+
| POWER(2, null) | POWER(null, 3) | POWER(null, null) |
+----------------+----------------+-------------------+
|           NULL |           NULL |              NULL |
+----------------+----------------+-------------------+

Missing Arguments

Calling POWER() with the wrong number of arguments, or without any arguments results in an error:

SELECT POWER();

Result:

ERROR 1582 (42000): Incorrect parameter count in the call to native function 'POWER'

And:

SELECT POWER(10, 2, 3);

Result:

ERROR 1582 (42000): Incorrect parameter count in the call to native function 'POWER'