Error
Error Code:
1460
MariaDB Error 1460: Aggregate Functions in Stored Functions
Description
This error occurs when you attempt to use aggregate functions such as SUM(), COUNT(), or AVG() directly within the definition of a MariaDB stored function. MariaDB stored functions are designed to return a single scalar value and do not support set-based operations like aggregation.
Error Message
AGGREGATE is not supported for stored functions
Known Causes
3 known causesDirect Aggregate Function Use
An aggregate function (e.g., SUM, COUNT, AVG) is explicitly called within the body of a `CREATE FUNCTION` statement.
Misunderstanding Function Scope
The stored function is designed with the expectation that it can perform set-based operations, which is a capability reserved for stored procedures or direct queries.
Incorrect SQL Migration
SQL code containing aggregate functions within a function-like construct was migrated from another database system that permits such usage, without adapting to MariaDB's specific limitations.
Solutions
Coming SoonGeneral Troubleshooting Tips
- Check the error message carefully for specific details
- Review recent changes that might have caused the error
- Search for the exact error code in the official documentation
- Check log files for additional context
- Try restarting the application or service