tursodatabase/turso · warning · anyhow::Error

Error retrieving columns for view

Error message

Error retrieving columns for view '{}': {}

What it means

Wrapper error from the CLI's view-column helper: it runs PRAGMA table_info(<view>) to collect column names (used for completion and schema listing) and any underlying failure is rethrown with the view name and original error (cli/app.rs:1490). A separate bail fires when the PRAGMA succeeds but returns zero columns.

Solutions

  1. Read the wrapped error text - it contains the exact PRAGMA failure reason
  2. Confirm the view still exists: SELECT name FROM sqlite_schema WHERE type='view'
  3. Refresh or reopen the connection so the schema cache is current, then retry
  4. For identifiers with special characters, quote them in the PRAGMA (see fix)

Example fix

// before
let pragma_sql = format!("PRAGMA table_info({view_name})");
// after
let pragma_sql = format!("PRAGMA table_info('{}')", view_name.replace('\'', "''"));
Defensive patterns

Strategy: try-catch

Validate before calling

let exists: bool = conn.query_row("SELECT COUNT(*) FROM sqlite_schema WHERE type='view' AND name=?", [view])?;
anyhow::ensure!(exists, "view {view} not present");

Try / catch

match get_view_columns(app, &view) {
    Ok(cols) => cols,
    Err(e) if e.to_string().contains("Error retrieving columns") => Vec::new(), // skip completion
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Tab-completing or listing columns of a view whose PRAGMA table_info fails: the view was dropped between schema read and PRAGMA execution, the view is malformed in sqlite_schema (corrupt schema), or the view name contains characters that break the unquoted interpolation into the PRAGMA.

Common situations: Another connection drops or recreates views while the shell is open; identifiers with spaces, hyphens, or keywords; schema corruption after a crash or partial write.

Related errors


AI-assisted analysis of tursodatabase/turso@492c4a71cd (2026-08-20). Data as JSON: /api/errors/49c58a23f592a1fc. Report an issue: GitHub.

Appendix: source

Thrown at cli/app.rs:1500

            false
        }
    }

    /// Get column names for a view to generate the SQLite-compatible comment
    fn get_view_columns(&mut self, view_name: &str) -> anyhow::Result<String> {
        // Get column information using PRAGMA table_info
        let pragma_sql = format!("PRAGMA table_info({view_name})");

        let mut columns = Vec::new();
        let handler = |row: &turso_core::Row| {
            // Column name is in the second column (index 1) of PRAGMA table_info
            if let Ok(Value::Text(col_name)) = row.get::<&Value>(1) {
                columns.push(col_name.as_str().to_string());
            }
            Ok(())
        };
        if let Err(err) = self.handle_row(&pragma_sql, handler) {
            return Err(anyhow::anyhow!(
                "Error retrieving columns for view '{}': {}",
                view_name,
                err
            ));
        }
        if columns.is_empty() {
            anyhow::bail!("PRAGMA table_info returned no columns for view '{}'. The view may be corrupted or the database schema is invalid.", view_name);
        }
        Ok(columns.join(","))
    }

    fn query_one_table_schema(
        &mut self,
        db_prefix: &str,
        db_display_name: &str,
        table_name: &str,
    ) -> anyhow::Result<bool> {
        // Yeah, sqlite also has this hardcoded: https://github.com/sqlite/sqlite/blob/31efe5a0f2f80a263457a1fc6524783c0c45769b/src/shell.c.in#L10765

View on GitHub (pinned to 492c4a71cd)