{"record":{"id":"6802250ccc45e258","repo":"MyCATApache/Mycat-Server","slug":"create-table-from-other-table-not-supported-680225","errorCode":null,"errorMessage":"\"create table from other table not supported :\" + stmt","messagePattern":"\"create table from other table not supported :\" \\+ stmt","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 Druid CREATE TABLE parser rejects CREATE TABLE ... AS SELECT / CREATE TABLE ... LIKE statements. When the parsed MySqlCreateTableStatement has a non-null query (i.e. the table is created from another table's result set), routing cannot proceed because Mycat does not support distributing a CTAS statement, so it throws SQLNonTransientException.","triggerScenarios":"Executing `CREATE TABLE new_table AS SELECT ... FROM old_table` (or any CREATE TABLE with a trailing query) against a Mycat-managed schema; statementParse detects createStmt.getQuery() != null and throws.","commonSituations":"Migrating DDL scripts written for a plain MySQL database straight to Mycat; schema-copy/idempotent migration tools (e.g. Flyway/Liquibase output) that emit CTAS; developers cloning tables during test setup.","solutions":["Rewrite as two statements: `CREATE TABLE new_table (...)` then `INSERT INTO new_table SELECT ... FROM old_table`","Execute the CTAS statement directly on each backend MySQL node, bypassing Mycat routing","Upgrade Mycat to a version that supports CTAS, if available","Create the table structure explicitly (showing CREATE from the source table) and copy data separately"],"exampleFix":"// before\nCREATE TABLE t2 AS SELECT * FROM t1;\n// after\nCREATE TABLE t2 LIKE t1_structure; -- or explicit DDL\nINSERT INTO t2 SELECT * FROM t1;","handlingStrategy":"try-catch","validationCode":"// reject CTAS before sending through Mycat\nString normalized = sql.replaceAll(\"\\\\s+\", \" \").toUpperCase();\nif (normalized.startsWith(\"CREATE TABLE\") && (normalized.contains(\" AS SELECT\") || normalized.contains(\" LIKE \"))) {\n    throw new IllegalArgumentException(\"CTAS not supported via Mycat: split DDL and DML\");\n}","typeGuard":"// Java: check before routing\nstatic boolean isCreateTableAsSelect(SQLStatement stmt) {\n    return stmt instanceof MySqlCreateTableStatement\n        && ((MySqlCreateTableStatement) stmt).getQuery() != null;\n}","tryCatchPattern":"try {\n    router.route(schema, rrs, stmt);\n} catch (SQLNonTransientException e) {\n    if (e.getMessage().startsWith(\"create table from other table not supported\")) {\n        throw new IllegalArgumentException(\"Split CREATE TABLE ... AS SELECT into DDL + INSERT ... SELECT\", e);\n    }\n    throw e;\n}","preventionTips":["Never send CREATE TABLE ... AS SELECT through Mycat","Keep migration tools (Flyway/Liquibase) configured to emit DDL and data copy as separate statements","Add a SQL pre-validation layer that rewrites CTAS before routing"],"tags":["sql","ddl","unsupported-feature","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"}