{"record":{"id":"49c58a23f592a1fc","repo":"tursodatabase/turso","slug":"error-retrieving-columns-for-view","errorCode":null,"errorMessage":"Error retrieving columns for view '{}': {}","messagePattern":"Error retrieving columns for view '(.+?)': (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"cli/app.rs","lineNumber":1477,"sourceCode":"            false\n        }\n    }\n\n    /// Get column names for a view to generate the SQLite-compatible comment\n    fn get_view_columns(&mut self, view_name: &str) -> anyhow::Result<String> {\n        // Get column information using PRAGMA table_info\n        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","sourceCodeStart":1459,"sourceCodeEnd":1495,"githubUrl":"https://github.com/tursodatabase/turso/blob/bad083fafbefdeae9a42ec19bdaaad8918dcf411/cli/app.rs#L1459-L1495","documentation":"Error returned by Shell::get_view_columns (cli/app.rs:1464-1487) when 'PRAGMA table_info(<view>)' itself fails while the CLI renders schema output for a view — it wants the column list for the SQLite-style '/* view(col1,col2) */' comment after printing the CREATE statement. The underlying PRAGMA failure text is appended. In the primary call site (app.rs:1452-1455) the error is already degraded with unwrap_or_else(|_| \"x\"), so .schema output usually just shows '/* view(x) */'; the raw error matters to other callers and as a symptom of deeper schema trouble.","triggerScenarios":"Running .schema (or completion/schema listing) against a view whose PRAGMA table_info errors: the view references objects that fail to resolve (missing attached database, unavailable virtual table module), the file is corrupted, or an encrypted database was opened without the correct key.","commonSituations":"Opening a database copied without its attached databases; schemas referencing vtabs from extensions that are not loaded; corrupted files after interrupted writes; encrypted DBs accessed without credentials.","solutions":["Run 'PRAGMA table_info(<view>);' manually in tursodb to see the underlying error verbatim","Run 'PRAGMA integrity_check;' and, for encrypted databases, reopen with the correct key","Restore or recreate the broken schema objects (re-attach databases, recreate the view once its dependencies load)"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"-- Run before relying on .schema / completion over views:\nPRAGMA integrity_check;\n-- and confirm the view itself resolves:\nPRAGMA table_info(your_view);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Open encrypted databases with the correct key before listing schema","Ensure attached databases and required virtual table modules are available before inspecting views","Treat '/* view(x) */' in .schema output as a signal that the view's PRAGMA failed — investigate it"],"tags":["rust","cli","pragma","schema","view"],"backgroundTag":"schema-introspection-failed","analyzedSha":"bad083fafbefdeae9a42ec19bdaaad8918dcf411","analyzedAt":"2026-08-16T23:12:11.798Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}