{"record":{"id":"d5d3f6e1c6205860","repo":"MyCATApache/Mycat-Server","slug":"create-table-from-other-table-not-supported","errorCode":null,"errorMessage":"create table from other table not supported :","messagePattern":"create table from other table not supported :","errorType":"exception","errorClass":"SQLNonTransientException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/route/parser/druid/impl/DruidCreateTableParser.java","lineNumber":35,"sourceCode":"import io.mycat.route.function.SlotFunction;\nimport io.mycat.route.parser.druid.MycatSchemaStatVisitor;\nimport io.mycat.util.StringUtil;\n\n\npublic class DruidCreateTableParser extends DefaultDruidParser {\n\n\t@Override\n\tpublic void visitorParse(SchemaConfig schema, RouteResultset rrs, SQLStatement stmt,\n\t\t\tMycatSchemaStatVisitor visitor) {\n\t}\n\t\n\t@Override\n\tpublic void statementParse(SchemaConfig schema, RouteResultset rrs, SQLStatement stmt) throws SQLNonTransientException {\n\t\tMySqlCreateTableStatement createStmt = (MySqlCreateTableStatement)stmt;\n\t\tif(createStmt.getQuery() != null) {\n\t\t\tString msg = \"create table from other table not supported :\" + stmt;\n\t\t\tLOGGER.warn(msg);\n\t\t\tthrow new SQLNonTransientException(msg);\n\t\t}\n\t\tString tableName = StringUtil.removeBackquote(createStmt.getTableSource().toString().toUpperCase());\n\t\tif(schema.getTables().containsKey(tableName)) {\n\t\t\tTableConfig tableConfig = schema.getTables().get(tableName);\n\t\t\tAbstractPartitionAlgorithm algorithm = tableConfig.getRule().getRuleAlgorithm();\n\t\t\tif(algorithm instanceof SlotFunction){\n\t\t\t\tSQLColumnDefinition column = new SQLColumnDefinition();\n\t\t\t\tcolumn.setDataType(new SQLCharacterDataType(\"int\"));\n\t\t\t\tcolumn.setName(new SQLIdentifierExpr(\"_slot\"));\n\t\t\t\tcolumn.setComment(new SQLCharExpr(\"自动迁移算法slot,禁止修改\"));\n\t\t\t\t((SQLCreateTableStatement)stmt).getTableElementList().add(column);\n\t\t\t\tString sql = createStmt.toString();\n\t\t\t\trrs.setStatement(sql);\n\t\t\t\tctx.setSql(sql);\n\t\t\t}\n\t\t}\n\t\tctx.addTable(tableName);\n\t\t","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/parser/druid/impl/DruidCreateTableParser.java#L17-L53","documentation":"Mycat's DruidCreateTableParser rejects CREATE TABLE ... AS SELECT / LIKE (statements carrying a query). Routing DDL that copies another table's data cannot be planned across sharded nodes, so the parser logs a warning and throws this SQLNonTransientException before any route is computed.","triggerScenarios":"Sending 'CREATE TABLE t2 AS SELECT ...' or any create-table-from-query statement through Mycat; detected in statementParse when MySqlCreateTableStatement.getQuery() != null.","commonSituations":"Schema migration scripts or ORM auto-DDL that use CTAS running against Mycat; SQL that works on standalone MySQL failing through the Mycat proxy.","solutions":["Rewrite as two statements: CREATE TABLE t2 (...) then INSERT INTO t2 SELECT ... .","Run the CTAS statement directly against the backend MySQL node, bypassing Mycat routing.","Create the target table explicitly with the same DDL as the source table instead of AS SELECT."],"exampleFix":"// before\nCREATE TABLE t2 AS SELECT * FROM t1;\n// after\nCREATE TABLE t2 (id INT, name VARCHAR(64));\nINSERT INTO t2 SELECT * FROM t1;","handlingStrategy":"validation","validationCode":"// Reject CTAS before routing through Mycat\nif (/^\\s*CREATE\\s+TABLE\\s+.+\\s+AS\\s+SELECT|CREATE\\s+TABLE\\s+.+\\s+LIKE\\s+/i.test(sql)) {\n  throw new Error(\"CREATE TABLE AS/LIKE is not supported through Mycat routing\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Express CTAS as explicit CREATE TABLE DDL followed by INSERT ... SELECT.","Audit migration/ORM DDL scripts for AS SELECT forms before pointing them at Mycat."],"tags":["ddl","create-table","unsupported-operation"],"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"}