Skip to content

Insert CSV with --detect-types crashes for CSV files that contain only a header row #702

Closed

Description

@nis-djom

I exported an empty table to csv, so that the csv file contains only the header row. When trying to create an SQLite DB file from that, using
sqlite-utils insert "$dbfile" "$table" "$csvfile" --csv --detect-types
I run into this error:
File "/root/.local/pipx/venvs/sqlite-utils/lib/python3.11/site-packages/sqlite_utils/cli.py", line 1244, in insert
insert_upsert_implementation(
File "/root/.local/pipx/venvs/sqlite-utils/lib/python3.11/site-packages/sqlite_utils/cli.py", line 1128, in insert_upsert_implementation
db[table].transform(types=tracker.types)
File "/root/.local/pipx/venvs/sqlite-utils/lib/python3.11/site-packages/sqlite_utils/db.py", line 1780, in transform
assert self.exists(), "Cannot transform a table that doesn't exist yet"
AssertionError: Cannot transform a table that doesn't exist yet

If I run it without --detect-types, then the issue naturally does not occur.
If --detect-types is going to be the default in the future, then I would suggest fixing this, for example by making the following change in cli.py on line 1179:
if tracker is not None and db.table(table).exists():

Activity

  1. added 2 commits that reference this issue on Feb 7, 2026
  2. added a commit that references this issue on Mar 7, 2026
    c0e30df
  3. added a commit that references this issue on May 18, 2026
    0c5e9eb
  4. added 2 commits that reference this issue on Jun 21, 2026
  5. added 2 commits that reference this issue on Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions