2 Ways to List all Functions in MariaDB

Below are two options for returning a list of functions in MariaDB.

The SHOW FUNCTION STATUS Command

The quickest way to list out all functions is to use the SHOW FUNCTION STATUS command.

Simply run the following to list out all functions:

SHOW FUNCTION STATUS;

The syntax goes like this:

SHOW FUNCTION STATUS
    [LIKE 'pattern' | WHERE expr]

So you can use a LIKE or WHERE clause to narrow down the results.

Example:

SHOW FUNCTION STATUS LIKE '%customer%';

Example result:

+--------+----------------------------+----------+------------------+---------------------+---------------------+---------------+---------+----------------------+----------------------+--------------------+
| Db     | Name                       | Type     | Definer          | Modified            | Created             | Security_type | Comment | character_set_client | collation_connection | Database Collation |
+--------+----------------------------+----------+------------------+---------------------+---------------------+---------------+---------+----------------------+----------------------+--------------------+
| sakila | get_customer_balance       | FUNCTION | barney@localhost | 2021-11-13 07:26:47 | 2021-11-13 07:26:47 | DEFINER       |         | utf8mb4              | utf8mb4_general_ci   | utf8mb4_general_ci |
| sakila | inventory_held_by_customer | FUNCTION | barney@localhost | 2021-11-13 07:26:47 | 2021-11-13 07:26:47 | DEFINER       |         | utf8mb4              | utf8mb4_general_ci   | utf8mb4_general_ci |
+--------+----------------------------+----------+------------------+---------------------+---------------------+---------------+---------+----------------------+----------------------+--------------------+

We can use the WHERE clause to filter the results by the columns. For example, we can filter the results to a given database:

SHOW FUNCTION STATUS WHERE db = 'music';

Example result:

+-------+------+----------+------------------+---------------------+---------------------+---------------+---------+----------------------+----------------------+--------------------+
| Db    | Name | Type     | Definer          | Modified            | Created             | Security_type | Comment | character_set_client | collation_connection | Database Collation |
+-------+------+----------+------------------+---------------------+---------------------+---------------+---------+----------------------+----------------------+--------------------+
| music | test | FUNCTION | barney@localhost | 2021-11-27 09:46:25 | 2021-11-27 09:46:25 | DEFINER       |         | utf8                 | utf8_general_ci      | utf8mb4_general_ci |
+-------+------+----------+------------------+---------------------+---------------------+---------------+---------+----------------------+----------------------+--------------------+

The SHOW FUNCTION STATUS command works very much like the SHOW PROCEDURE STATUS command, which returns a list of stored procedures.

The information_schema.routines Table

Another way to get a list of functions in MariaDB is to query the information_schema.routines table.

Example:

SELECT 
    routine_schema as "Database",
    routine_name
FROM 
    information_schema.routines
WHERE 
    routine_type = 'FUNCTION'
ORDER BY 
    routine_schema ASC, 
    routine_name ASC;

Example result:

+----------+----------------------------+
| Database | routine_name               |
+----------+----------------------------+
| music    | test                       |
| sakila   | get_customer_balance       |
| sakila   | inventory_held_by_customer |
| sakila   | inventory_in_stock         |
+----------+----------------------------+

This table also stores information about stored procedures. In the above example, I excluded those by using a WHERE clause to return only functions (i.e. objects with a routine_type of FUNCTION).

To include stored procedures we can remove the WHERE clause:

SELECT 
    routine_schema as "Database",
    routine_name,
    routine_type
FROM 
    information_schema.routines
ORDER BY 
    routine_schema ASC, 
    routine_name ASC;

In this case I also added the routine_type column so that we can distinguish between the procedures and functions.

We can also narrow it down to a specific database:

SELECT 
    routine_schema as "Database",
    routine_name,
    routine_type
FROM 
    information_schema.routines
WHERE 
    routine_schema = 'sakila'
ORDER BY 
    routine_name ASC;

Result:

+----------+----------------------------+--------------+
| Database | routine_name               | routine_type |
+----------+----------------------------+--------------+
| sakila   | film_in_stock              | PROCEDURE    |
| sakila   | film_not_in_stock          | PROCEDURE    |
| sakila   | get_customer_balance       | FUNCTION     |
| sakila   | inventory_held_by_customer | FUNCTION     |
| sakila   | inventory_in_stock         | FUNCTION     |
| sakila   | rewards_report             | PROCEDURE    |
+----------+----------------------------+--------------+