tursodatabase/turso · warning

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

Error message

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

What it means

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.

Source

Thrown at cli/app.rs:1477

            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 bad083fafb)

Solutions

  1. Run 'PRAGMA table_info(<view>);' manually in tursodb to see the underlying error verbatim
  2. Run 'PRAGMA integrity_check;' and, for encrypted databases, reopen with the correct key
  3. Restore or recreate the broken schema objects (re-attach databases, recreate the view once its dependencies load)
Defensive patterns

Strategy: validation

Validate before calling

-- Run before relying on .schema / completion over views:
PRAGMA integrity_check;
-- and confirm the view itself resolves:
PRAGMA table_info(your_view);

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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