You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
insert --csv and memory silently drop values when column names are duplicated #986
Inserted a CSV file whose header row contains the same column name twice:
name,namedog,cat
sqlite-utils insert data.db data example.csv --csv
sqlite-utils rows data.db data --nl
What I expected
An error. Two CSV columns cannot map to one SQLite column, and CREATE TABLE already rejects duplicate column names, so the import should not proceed silently.
What actually happened
Only the last value was kept, and the first was lost, with exit code 0:
{"name": "cat"}
sqlite-utils memory example.csv "select * from example" does the same, because csv.DictReader keeps only the last duplicate header.
The CLI builds rows with dict(zip(headers, row)) in insert_upsert_implementation, which collapses the duplicate before SQLite sees it. rows_from_file() uses csv.DictReader, which does the same.
Environment
sqlite-utils 4.2.2 (also on main)
Python 3.14.8, Windows 10
SQLite 3.50.4
Possible fix
Reject duplicate headers in insert / upsert and rows_from_file() with a clear error instead of silently dropping values.
I tested an additional regression case for #987: a malformed CSV passed to insert --csv --truncate should fail without deleting rows from the existing table.
Starting each run with a fresh temporary database containing data(name) and one row, "keep me":
printf'name,name\ndog,cat\n'| sqlite-utils insert test.db data - --csv --truncate
sqlite-utils rows test.db data --nl
Released 4.2.2: the import exits 0 and the existing row is replaced with {"name":"cat"}.
I also ran a control against that PR: insert --csv --no-headers still accepts the same bytes and stores name,name as data under untitled_1 and untitled_2. That distinguishes rejecting duplicate headers from rejecting repeated values. An assertion that the pre-existing row survives would complement the PR's current assertion that a new table is not created.
I’m chcbz, the maintainer of Kit. I used OpenAI Codex to assist with the reproduction and drafting; the tests used only synthetic data.
Activity
chcbz commentedon Dec 5, 2026
I tested an additional regression case for #987: a malformed CSV passed to
insert --csv --truncateshould fail without deleting rows from the existing table.Starting each run with a fresh temporary database containing
data(name)and one row,"keep me":{"name":"cat"}.7e34d89: the import exits 1 withError: Duplicate column names: name, and the original{"name":"keep me"}row is still present.I also ran a control against that PR:
insert --csv --no-headersstill accepts the same bytes and storesname,nameas data underuntitled_1anduntitled_2. That distinguishes rejecting duplicate headers from rejecting repeated values. An assertion that the pre-existing row survives would complement the PR's current assertion that a new table is not created.I’m chcbz, the maintainer of Kit. I used OpenAI Codex to assist with the reproduction and drafting; the tests used only synthetic data.