{"record":{"id":"372675f16c9635d2","repo":"MyCATApache/Mycat-Server","slug":"todo-insert-into-select-not-supported","errorCode":null,"errorMessage":"TODO:insert into .... select .... not supported!","messagePattern":"TODO:insert into \\.\\.\\.\\. select \\.\\.\\.\\. not supported!","errorType":"exception","errorClass":"SQLNonTransientException","httpStatus":null,"severity":"warning","filePath":"src/main/java/io/mycat/route/parser/druid/impl/DruidInsertParser.java","lineNumber":324,"sourceCode":"\t\t\t\t\t\tnodes[count] = new RouteResultsetNode(tableConfig.getDataNodes().get(nodeIndex),\n\t\t\t\t\t\t\t\trrs.getSqlType(),insertStmt.toString());\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tif(algorithm instanceof SlotFunction) {\n\t\t\t\t\t\tnodes[count].setSlot(slotsMap.get(nodeIndex));\n\t\t\t\t\t\tnodes[count].setStatement(ParseUtil.changeInsertAddSlot(nodes[count].getStatement(),nodes[count].getSlot()));\n\t\t\t\t\t}\n\t\t\t\t\tnodes[count++].setSource(rrs);\n\n\t\t\t\t}\n\t\t\t\trrs.setNodes(nodes);\n\t\t\t\trrs.setFinishedRoute(true);\n\n\t\t\t}\n\t\t} else if(insertStmt.getQuery() != null) { // insert into .... select ....\n\t\t\tString msg = \"TODO:insert into .... select .... not supported!\";\n\t\t\tLOGGER.warn(msg);\n\t\t\tthrow new SQLNonTransientException(msg);\n\t\t}\n\t}\n\n\tprivate String getShardingValue(SQLExpr expr) throws SQLNonTransientException {\n\t\tString shardingValue = null;\n\t\tif(expr instanceof SQLIntegerExpr) {\n\t\t\tSQLIntegerExpr intExpr = (SQLIntegerExpr)expr;\n\t\t\tshardingValue = intExpr.getNumber() + \"\";\n\t\t} else if (expr instanceof SQLCharExpr) {\n\t\t\tSQLCharExpr charExpr = (SQLCharExpr)expr;\n\t\t\tshardingValue = charExpr.getText();\n\t\t} else if (expr instanceof SQLMethodInvokeExpr) {\n\t\t\tSQLMethodInvokeExpr methodInvokeExpr = (SQLMethodInvokeExpr)expr;\n\t\t\ttry {\n\t\t\t\tshardingValue = tryInvokeSQLMethod(methodInvokeExpr);\n\t\t\t}catch (Exception e){\n\t\t\t\tLOGGER.error(\"\",e);\n\t\t\t}","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/parser/druid/impl/DruidInsertParser.java#L306-L342","documentation":"DruidInsertParser does not implement routing for INSERT INTO ... SELECT statements. When the parsed SQLInsertStatement has a query part (a SELECT source instead of VALUES), it throws SQLNonTransientException with a literal TODO message.","triggerScenarios":"statementParse -> parserBatchInsert (or the insert parse path) receives `INSERT INTO t SELECT ...` — insertStmt.getQuery() != null.","commonSituations":"Migration scripts using INSERT...SELECT to copy data; ORM or ETL tools generating INSERT-SELECT; developers assuming MyCat passes arbitrary SQL through to MySQL.","solutions":["Rewrite as a plain INSERT with explicit VALUES","Split into SELECT first, then INSERT per row from the application","Execute the INSERT...SELECT directly on the datanode's MySQL, bypassing MyCat routing","Upgrade MyCat versions — check release notes for INSERT-SELECT support"],"exampleFix":"// before\nINSERT INTO t SELECT id, name FROM src;\n// after\nSELECT id, name FROM src; -- then INSERT INTO t VALUES (...) per row from client\n","handlingStrategy":"try-catch","validationCode":"if (sql.matches(\"(?is)\\\\s*insert\\\\s+.*\\\\bselect\\\\b.*\")) throw new UnsupportedSqlException(\"INSERT...SELECT not supported by MyCat router\");","typeGuard":null,"tryCatchPattern":"try { route(sql); } catch (SQLNonTransientException e) { if (e.getMessage().contains(\"insert into .... select\")) { fallbackToClientSideInsert(sql); } else throw e; }","preventionTips":["Ban INSERT...SELECT in code review for MyCat-fronted schemas","Implement ETL copy logic in the application instead of SQL","Document the limitation for DBAs writing migration scripts"],"tags":["sql","insert","unsupported","mycat"],"backgroundTag":"unsupported-operation","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}