MyCATApache/Mycat-Server · error · SQLNonTransientException
unsupported mysql function expression
Error message
unsupported mysql function expression: {expr} What it means
MysqlMethodInvocationHandler rewrites supported MySQL function expressions (NOW, ADDDATE, etc.) during SQL parsing. If a method-invoke expression is not one of the supported functions (doInvoke returns null), invoke() throws this error with the original expression text.
Solutions
- Replace the unsupported function with a supported one (e.g. use NOW() instead of an unmapped time function) or compute the value in the application and pass it as a literal
- Add a case for the function in MysqlMethodInvocationHandler.doInvoke that returns the rewritten expression
- Downgrade or rewrite the SQL/rule expression to use only functions listed in the switch
Example fix
// before (rule expression) DATE_FORMAT(create_time, '%Y%m') // after -- compute in app or use a supported function YEAR(create_time)*100 + MONTH(create_time)
Defensive patterns
Strategy: try-catch
Validate before calling
private static final Set<String> SUPPORTED = Set.of("NOW","ADDDATE","SUBDATE", /* ... */);
if (!SUPPORTED.contains(fn.toUpperCase())) {
throw new IllegalArgumentException("function not supported by Mycat parser: " + fn);
} Try / catch
try { String v = handler.invoke(methodInvokeExpr); } catch (SQLNonTransientException e) { if (e.getMessage().startsWith("unsupported mysql function expression")) { evaluateInAppAndInlineLiteral(); } } Prevention
- Use only functions listed in MysqlMethodInvocationHandler's switch in rule expressions
- Compute complex functions in the application and pass literals
- Keep a compatibility list when upgrading MySQL versions
When it happens
Trigger: Routing SQL containing a MySQL function not in the handler's switch (methodName.toUpperCase() has no case), e.g. UNIX_TIMESTAMP with args, DATE_FORMAT, or user-defined functions, wherever the handler is applied (e.g. in partition/routing expression evaluation).
Common situations: Newer MySQL functions used in rule/partition expressions; UDFs; less-common date functions in default-value or routing expressions; upgrading MySQL and adopting functions Mycat doesn't map.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- can't connect to mysql server ,errmsg
- "can't find hint datanode:" + hintSQLValue
- "can't find hint schema:" + hintSQLValue
- "can't find table define of " + table + " in schema:" +…
- columnValue: Please check if the format satisfied.
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/e69e2caa4eb02336.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/route/parser/druid/impl/MysqlMethodInvocationHandler.java:41
*
* @author zhuyiqiang
* @version 2018/9/3
*/
public class MysqlMethodInvocationHandler implements SqlMethodInvocationHandler {
protected static final Logger LOGGER = LoggerFactory.getLogger(MysqlMethodInvocationHandler.class);
private final String[] SUPPORT_PATTERNS = {
"yyyy-MM-dd HH:mm:ss",
"yyyy-MM-dd",
"yyyy-MM-dd HH:mm"
};
@Override
public String invoke(SQLMethodInvokeExpr expr) throws SQLNonTransientException {
SQLExpr ret = doInvoke(expr);
if (ret != null) {
return ret.toString();
}
throw new SQLNonTransientException("unsupported mysql function expression: " + expr.toString());
}
private SQLExpr doInvoke(SQLMethodInvokeExpr expr) throws SQLNonTransientException {
String methodName = expr.getMethodName().toUpperCase();
switch (methodName) {
case "NOW":
case "SYSDATE":
case "CURRENT_TIMESTAMP":
return invokeNow();
case "ADDDATE":
case "DATE_ADD":
return invokeAddDate(expr, false);
case "SUBDATE":
case "DATE_SUB":
return invokeAddDate(expr, true);
}
return null;
}View on GitHub (pinned to 65f8d8beb7)