MariaDB LOG() Function

In MariaDB, LOG() is a built-in function that returns the logarithm of a specified number to a specified base.

Please refer to EXP() and LN().

MariaDB LOG() Syntax

Here is the syntax of the MariaDB LOG() function:

LOG(number)
LOG(base, number)

LOG(number) is equivalent to LN(number).

Parameters

number

Required. A number used to calculate the logarithm. The value must be greater than 0.

base

Optional. The Base number. The value must be greater than 1. The default is the natural base e .

If you provide the wrong number of parameters, MariaDB will report an error: ERROR 1582 (42000): Incorrect parameter count in the call to native function 'LOG'.

Return value

The MariaDB LOG() function returns the logarithm of the specified number to the specified base.

If the parameter number is less than or equal to 0, the LOG() function will return NULL.

If the parameter base is less than or equal to 1, the LOG() function will return NULL.

If any parameter is NULL, the LOG() function will return NULL.

MariaDB LOG() Examples

This statement shows the basic usage of the MariaDB LOG() function:

SELECT
    LOG(1),
    LOG(EXP(1), 1),
    LOG(2),
    LOG(EXP(1), 2),
    LOG(2, 16),
    LOG(10, 100),
    LOG(0),
    LOG(-1),
    LOG(1, 10),
    LOG(NULL)\G

Output:

        LOG(1): 0
LOG(EXP(1), 1): 0
        LOG(2): 0.6931471805599453
LOG(EXP(1), 2): 0.6931471805599453
    LOG(2, 16): 4
  LOG(10, 100): 2
        LOG(0): NULL
       LOG(-1): NULL
    LOG(1, 10): NULL
     LOG(NULL): NULL

Conclusion

In MariaDB, LOG() is a built-in function that returns the logarithm of a specified number to a specified base.