benbjohnson/litestream · error
get table info: %w
Error message
get table info: %w
What it means
This error wraps a failure of the `PRAGMA table_info(<table>)` query that `deleteFromTable` uses to discover whether the table has an `id` column. It means SQLite rejected the PRAGMA — typically because the table does not exist or the table name breaks the PRAGMA syntax (PRAGMA arguments cannot be parameterized, so the name is interpolated raw).
Source
Thrown at cmd/litestream-test/shrink.go:191
countQuery := fmt.Sprintf("SELECT COUNT(*) FROM %s", table)
if err := db.QueryRow(countQuery).Scan(&totalRows); err != nil {
return 0, fmt.Errorf("count rows: %w", err)
}
if totalRows == 0 {
return 0, nil
}
rowsToDelete := int(float64(totalRows) * (c.DeletePercentage / 100))
if rowsToDelete == 0 {
return 0, nil
}
var hasID bool
columnQuery := fmt.Sprintf("PRAGMA table_info(%s)", table)
rows, err := db.Query(columnQuery)
if err != nil {
return 0, fmt.Errorf("get table info: %w", err)
}
defer rows.Close()
for rows.Next() {
var cid int
var name, dtype string
var notnull, pk int
var dflt sql.NullString
if err := rows.Scan(&cid, &name, &dtype, ¬null, &dflt, &pk); err != nil {
continue
}
if name == "id" || pk == 1 {
hasID = true
break
}
}
var deleteQuery stringView on GitHub (pinned to 4ed7a308f6)
Solutions
- Confirm the exact table name exists via `sqlite3 <db> '.schema <table>'`
- Avoid special characters in table names, or wrap the name in double quotes in the PRAGMA
- Close competing connections that may hold locks on the database
- Inspect the wrapped driver error (`%w`) for the precise SQLite error code
Example fix
// before
columnQuery := fmt.Sprintf("PRAGMA table_info(%s)", table)
// after
columnQuery := fmt.Sprintf("PRAGMA table_info(%q)", table) Defensive patterns
Strategy: validation
Validate before calling
var exists int
db.QueryRow("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name=?", table).Scan(&exists)
if exists == 0 { return fmt.Errorf("table %q not found", table) } Prevention
- Use simple identifier-safe table names
- Verify schema with .schema before running PRAGMA-based tooling
- Read wrapped driver errors for exact SQLite code
When it happens
Trigger: Table name absent from the database; table name containing quotes/parentheses/spaces that break `PRAGMA table_info(name)`; database locked so the query fails; driver-level error opening rows (`db.Query`) on a corrupted DB.
Common situations: Passing hyphenated or space-containing table names to `litestream-test shrink`; typo in `--table` flag; shrink running against a freshly created (empty) database file where no tables exist yet.
Understand the failure class
Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.
Related errors
AI-assisted analysis of benbjohnson/litestream@4ed7a308f6 (2026-09-06).
Data as JSON: /api/errors/c7061580f2b894a3.
Report an issue: GitHub.