tursodatabase/turso · error
PRAGMA table_info returned no columns for view '{}'. The vie
Error message
PRAGMA table_info returned no columns for view '{}'. The view may be corrupted or the database schema is invalid. What it means
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.
Source
Thrown at cli/app.rs:1484
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
match table_name {
"sqlite_master" | "sqlite_schema" | "sqlite_temp_master" | "sqlite_temp_schema" => {
let schema = format!(
"CREATE TABLE {table_name} (\n type text,\n name text,\n tbl_name text,\n rootpage integer,\n sql text\n);",
);
let _ = self.writeln(&schema);
return Ok(true);View on GitHub (pinned to bad083fafb)
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.
Example fix
-- before: schema entry exists but columns cannot be resolved .schema broken_view -- Error: PRAGMA table_info returned no columns for view 'broken_view'... -- after: drop and recreate the view from its stored SQL DROP VIEW broken_view; CREATE VIEW broken_view AS SELECT id, name FROM t; .schema broken_view
Defensive patterns
Strategy: fallback
Validate before calling
-- Run before rendering a view's schema; skip the column comment when empty:
SELECT count(*) FROM pragma_table_info('myview'); -- 0 means the error would fire Try / catch
// Mirror what the CLI itself does at the call site (app.rs:1452): let columns = self.get_view_columns(view).unwrap_or_else(|_| "x".to_string()); // Render the schema comment with the fallback instead of propagating the error.
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Error retrieving columns for view '{}': {}
- Unable to access database schema. The database may be using
- Error querying schema: {}
- Error in database list: {}
- Expected first argument to be a string
AI-assisted analysis of tursodatabase/turso@bad083fafb (2026-08-16).
Data as JSON: /api/errors/5f7cb0de01025b69.
Report an issue: GitHub.