Lab-verifiedReproduced and fixed on MySQL 8.4.13 · 2026-11-29 · container image mysql:8.4
SUM, MAX, COUNT and other aggregate functions must be followed directly by (. With a space, as in SUM (amount), MySQL 8.4 does not treat it as the built-in function. It looks for a user-defined function in the current database instead and reports ERROR 1630 FUNCTION lab_a.SUM does not exist.
The lab_a. in the message is just the current database name. Nobody tried to create a function called SUM. The message is in English only; MySQL has no Korean or Japanese translation for it.
01A space between SUM and the parenthesis
SELECT SUM (amount) AS total FROM orders; failed with FUNCTION lab_a.SUM does not exist. Removing the single space, SUM(amount), returned 3900.
The same rule applies to every aggregate in the query. COUNT(*), SUM(amount) and MAX(amount) written without spaces returned 3, 3900 and 2500.
Setup
CREATE TABLE orders (id INT PRIMARY KEY, amount INT);
INSERT INTO orders VALUES (1, 1000), (2, 2500), (3, 400);Query OK, 0 rows affected (0.01 sec)
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0SELECT SUM (amount) AS total FROM orders;ERROR 1630 (42000): FUNCTION lab_a.SUM does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference ManualSELECT SUM(amount) AS total FROM orders;+-------+
| total |
+-------+
| 3900 |
+-------+
1 row in set (0.00 sec)This often comes from SQL formatters or code copied from other databases. Search the query for SUM (, MAX (, COUNT ( and similar.
SELECT COUNT(*) AS cnt, SUM(amount) AS total, MAX(amount) AS max_amount FROM orders;+-----+-------+------------+
| cnt | total | max_amount |
+-----+-------+------------+
| 3 | 3900 | 2500 |
+-----+-------+------------+
1 row in set (0.00 sec)02IGNORE_SPACE is not in sql_mode
Whether a space is allowed depends on the IGNORE_SPACE flag in sql_mode. SELECT @@sql_mode; showed the MySQL 8.4 default ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION, without IGNORE_SPACE, so MAX (amount) and MIN (amount) failed with ERROR 1630.
After SET SESSION sql_mode = CONCAT(@@sql_mode, ',IGNORE_SPACE'); the same query, spaces and all, returned 2500 and 400.
Setup
CREATE TABLE orders (id INT PRIMARY KEY, amount INT);
INSERT INTO orders VALUES (1, 1000), (2, 2500), (3, 400);Query OK, 0 rows affected (0.01 sec)
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0SELECT MAX (amount) AS max_amount, MIN (amount) AS min_amount FROM orders;ERROR 1630 (42000): FUNCTION lab_a.MAX does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference ManualSELECT @@sql_mode;+-----------------------------------------------------------------------------------------------------------------------+
| @@sql_mode |
+-----------------------------------------------------------------------------------------------------------------------+
| ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION |
+-----------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)This only changed the current session. Use it when you cannot edit the SQL right away; removing the spaces is the simpler fix.
SET SESSION sql_mode = CONCAT(@@sql_mode, ',IGNORE_SPACE');
SELECT MAX (amount) AS max_amount, MIN (amount) AS min_amount FROM orders;Query OK, 0 rows affected (0.00 sec)
+------------+------------+
| max_amount | min_amount |
+------------+------------+
| 2500 | 400 |
+------------+------------+
1 row in set (0.00 sec)FAQ
Why does MySQL say FUNCTION SUM does not exist?
Usually there is a space between SUM and (. Without IGNORE_SPACE in sql_mode, MySQL reads SUM ( as a call to a stored function named SUM in the current database. SUM(amount) worked right away.
What does the database name in 'FUNCTION lab_a.SUM' mean?
It is the current database. MySQL searched for a user-defined function SUM there. You do not need to create anything; fix the spacing.
Can I allow a space before the parenthesis?
Yes, by adding IGNORE_SPACE to sql_mode. On this page SET SESSION sql_mode = CONCAT(@@sql_mode, ',IGNORE_SPACE'); made MAX (amount) work in that session.
Is IGNORE_SPACE on by default in MySQL 8.4?
No. SELECT @@sql_mode; on the default MySQL 8.4 container did not include it.
How we verify
Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.
lab_a and lab_b are ordinary users created for the test, each with full rights on a database of the same name (its default database); root is the administrator. MySQL 8.4.13