{"record":{"id":"5f7cb0de01025b69","repo":"tursodatabase/turso","slug":"pragma-table-info-returned-no-columns-for-view","errorCode":null,"errorMessage":"PRAGMA table_info returned no columns for view '{}'. The view may be corrupted or the database schema is invalid.","messagePattern":"PRAGMA table_info returned no columns for view '(.+?)'\\. The view may be corrupted or the database schema is invalid\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/app.rs","lineNumber":1484,"sourceCode":"        let pragma_sql = format!(\"PRAGMA table_info({view_name})\");\n\n        let mut columns = Vec::new();\n        let handler = |row: &turso_core::Row| {\n            // Column name is in the second column (index 1) of PRAGMA table_info\n            if let Ok(Value::Text(col_name)) = row.get::<&Value>(1) {\n                columns.push(col_name.as_str().to_string());\n            }\n            Ok(())\n        };\n        if let Err(err) = self.handle_row(&pragma_sql, handler) {\n            return Err(anyhow::anyhow!(\n                \"Error retrieving columns for view '{}': {}\",\n                view_name,\n                err\n            ));\n        }\n        if columns.is_empty() {\n            anyhow::bail!(\"PRAGMA table_info returned no columns for view '{}'. The view may be corrupted or the database schema is invalid.\", view_name);\n        }\n        Ok(columns.join(\",\"))\n    }\n\n    fn query_one_table_schema(\n        &mut self,\n        db_prefix: &str,\n        db_display_name: &str,\n        table_name: &str,\n    ) -> anyhow::Result<bool> {\n        // Yeah, sqlite also has this hardcoded: https://github.com/sqlite/sqlite/blob/31efe5a0f2f80a263457a1fc6524783c0c45769b/src/shell.c.in#L10765\n        match table_name {\n            \"sqlite_master\" | \"sqlite_schema\" | \"sqlite_temp_master\" | \"sqlite_temp_schema\" => {\n                let schema = format!(\n                                    \"CREATE TABLE {table_name} (\\n type text,\\n name text,\\n tbl_name text,\\n rootpage integer,\\n sql text\\n);\",\n                                );\n                let _ = self.writeln(&schema);\n                return Ok(true);","sourceCodeStart":1466,"sourceCodeEnd":1502,"githubUrl":"https://github.com/tursodatabase/turso/blob/bad083fafbefdeae9a42ec19bdaaad8918dcf411/cli/app.rs#L1466-L1502","documentation":"Thrown by the CLI helper get_view_columns (cli/app.rs:1464) while rendering '.schema' output for a view. It runs PRAGMA table_info(<view>) to build the SQLite-compatible '/* view(col1,col2) */' comment; if the pragma yields zero rows, the view's column list cannot be resolved and the CLI treats it as a broken schema entry rather than printing an empty column list.","triggerScenarios":"Running '.schema' on a database where a CREATE VIEW row exists in sqlite_schema but PRAGMA table_info(<view>) returns no rows: a view whose SELECT body can no longer be resolved, a truncated/corrupted schema row, or a database hand-edited or partially written by another tool.","commonSituations":"Opening a database produced by a broken or incompatible tool; a file corrupted by an interrupted write or bad copy; a view created against tables or extensions that no longer exist so the column list cannot be derived.","solutions":["Run PRAGMA integrity_check; on the database to test the file.","Inspect the raw schema row: SELECT name, sql FROM sqlite_schema WHERE type='view' AND name='<view>';","Drop and recreate the view from its stored SQL (DROP VIEW v; CREATE VIEW v AS ...).","If the file itself is corrupt, restore from a backup or salvage readable data with .dump before re-importing."],"exampleFix":"-- before: schema entry exists but columns cannot be resolved\n.schema broken_view\n-- Error: PRAGMA table_info returned no columns for view 'broken_view'...\n\n-- after: drop and recreate the view from its stored SQL\nDROP VIEW broken_view;\nCREATE VIEW broken_view AS SELECT id, name FROM t;\n.schema broken_view","handlingStrategy":"fallback","validationCode":"-- Run before rendering a view's schema; skip the column comment when empty:\nSELECT count(*) FROM pragma_table_info('myview'); -- 0 means the error would fire","typeGuard":null,"tryCatchPattern":"// Mirror what the CLI itself does at the call site (app.rs:1452):\nlet columns = self.get_view_columns(view).unwrap_or_else(|_| \"x\".to_string());\n// Render the schema comment with the fallback instead of propagating the error.","preventionTips":["Run PRAGMA integrity_check after any suspected corruption event before using .schema.","Validate views right after CREATE VIEW with PRAGMA table_info(v) so breakage is caught early.","Keep schema DDL in version-controlled migration files so a broken view can be recreated exactly."],"tags":["cli","schema","views","pragma","corruption"],"backgroundTag":"schema-corruption","analyzedSha":"bad083fafbefdeae9a42ec19bdaaad8918dcf411","analyzedAt":"2026-08-16T23:12:11.798Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}