{"record":{"id":"f8662c686c8aad22","repo":"tursodatabase/turso","slug":"unexpected-row-for-create-table","errorCode":null,"errorMessage":"Unexpected row for CREATE TABLE","messagePattern":"Unexpected row for CREATE TABLE","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/commands/import.rs","lineNumber":111,"sourceCode":"                let create_table = format!(\"CREATE TABLE {} ({});\", args.table, columns);\n\n                let rows = match self.conn.query(create_table) {\n                    Ok(rows) => rows,\n                    Err(e) => {\n                        let _ = self\n                            .writer\n                            .write_all(format!(\"Error creating table: {e:?}\\n\").as_bytes());\n                        return;\n                    }\n                };\n                let Some(mut rows) = rows else {\n                    let _ = self.writer.write_all(b\"Error creating table\\n\");\n                    return;\n                };\n\n                let res = rows.run_with_row_callback(|_| {\n                    // Not expected for CREATE TABLE\n                    panic!(\"Unexpected row for CREATE TABLE\");\n                });\n                match res {\n                    Ok(_) => {}\n                    Err(LimboError::Busy | LimboError::Interrupt) => {\n                        let _ = self\n                            .writer\n                            .write_all(\"Error creating table: interrupted / busy\\n\".as_bytes());\n                        return;\n                    }\n                    Err(e) => {\n                        let _ = self.writer.write_all(\n                            format!(\"Error checking table existence: {e:?}\\n\").as_bytes(),\n                        );\n                        return;\n                    }\n                }\n            } else {\n                let _ = self.writer.write_all(b\"Error: Empty input file\\n\");","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/tursodatabase/turso/blob/c1e59287258d99b309e362a63f48822256e2f65f/cli/commands/import.rs#L93-L129","documentation":"During `tursodb import`, the importer executes the generated CREATE TABLE through conn.query plus run_with_row_callback. DDL must not yield rows, so any row callback invocation panics. Hitting it means the engine returned rows for a DDL statement (or the constructed statement was not actually DDL) - an internal invariant break, not a user configuration error.","triggerScenarios":"Running `tursodb import file.csv --table name` on a build where statement execution returns rows for CREATE TABLE; CSV-header identifiers that make the generated CREATE TABLE degenerate into something row-returning; planner/executor regressions in statement classification.","commonSituations":"Nightly or regression builds of the CLI; exotic column names from CSV headers; testing import right after engine changes to statement handling.","solutions":["Upgrade to a build where the regression is fixed; if it reproduces on latest, file an issue with the CSV header and exact command","Pre-create the table yourself and import into it, skipping the CREATE TABLE path","Normalize or quote CSV header identifiers before importing"],"exampleFix":"# before\ntursodb import data.csv --table users   # panics: Unexpected row for CREATE TABLE\n\n# after\n# pre-create the schema so the importer does not run DDL\nsqlite3 new.db 'CREATE TABLE users(id INTEGER PRIMARY KEY, name TEXT);'\ntursodb import data.csv --table users","handlingStrategy":"fallback","validationCode":"# smoke-test that DDL on this build yields no rows before importing real data\nprintf 'CREATE TABLE _probe(x);\\n' | tursodb >/dev/null && echo ddl-ok","typeGuard":null,"tryCatchPattern":"import subprocess\nrc = subprocess.run(['tursodb','import','data.csv','--table','users']).returncode\nif rc != 0:\n    # fall back: create schema via sqlite3, or import there entirely\n    ...","preventionTips":["Import a 5-row sample CSV first to validate the path before large files","Pre-create tables with known-good schemas so the importer skips DDL"],"tags":["cli","import","csv","ddl","invariant","panic"],"backgroundTag":"internal-invariant-violation","analyzedSha":"c1e59287258d99b309e362a63f48822256e2f65f","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}