{"record":{"id":"e69e2caa4eb02336","repo":"MyCATApache/Mycat-Server","slug":"unsupported-mysql-function-expression-expr","errorCode":null,"errorMessage":"unsupported mysql function expression: {expr}","messagePattern":"unsupported mysql function expression: (.+?)","errorType":"exception","errorClass":"SQLNonTransientException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/route/parser/druid/impl/MysqlMethodInvocationHandler.java","lineNumber":41,"sourceCode":" *\n * @author zhuyiqiang\n * @version 2018/9/3\n */\npublic class MysqlMethodInvocationHandler implements SqlMethodInvocationHandler {\n    protected static final Logger LOGGER = LoggerFactory.getLogger(MysqlMethodInvocationHandler.class);\n    private final String[] SUPPORT_PATTERNS = {\n            \"yyyy-MM-dd HH:mm:ss\",\n            \"yyyy-MM-dd\",\n            \"yyyy-MM-dd HH:mm\"\n    };\n\n    @Override\n    public String invoke(SQLMethodInvokeExpr expr) throws SQLNonTransientException {\n        SQLExpr ret = doInvoke(expr);\n        if (ret != null) {\n            return ret.toString();\n        }\n        throw new SQLNonTransientException(\"unsupported mysql function expression: \" + expr.toString());\n    }\n\n    private SQLExpr doInvoke(SQLMethodInvokeExpr expr) throws SQLNonTransientException {\n        String methodName = expr.getMethodName().toUpperCase();\n        switch (methodName) {\n            case \"NOW\":\n            case \"SYSDATE\":\n            case \"CURRENT_TIMESTAMP\":\n                return invokeNow();\n            case \"ADDDATE\":\n            case \"DATE_ADD\":\n                return invokeAddDate(expr, false);\n            case \"SUBDATE\":\n            case \"DATE_SUB\":\n                return invokeAddDate(expr, true);\n        }\n        return null;\n    }","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/parser/druid/impl/MysqlMethodInvocationHandler.java#L23-L59","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before (rule expression)\nDATE_FORMAT(create_time, '%Y%m')\n// after\n-- compute in app or use a supported function\nYEAR(create_time)*100 + MONTH(create_time)","handlingStrategy":"try-catch","validationCode":"private static final Set<String> SUPPORTED = Set.of(\"NOW\",\"ADDDATE\",\"SUBDATE\", /* ... */);\nif (!SUPPORTED.contains(fn.toUpperCase())) {\n    throw new IllegalArgumentException(\"function not supported by Mycat parser: \" + fn);\n}","typeGuard":null,"tryCatchPattern":"try { String v = handler.invoke(methodInvokeExpr); } catch (SQLNonTransientException e) { if (e.getMessage().startsWith(\"unsupported mysql function expression\")) { evaluateInAppAndInlineLiteral(); } }","preventionTips":["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"],"tags":["mysql","sql-function","parsing"],"backgroundTag":"unsupported-operation","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}