Skip to content

Reject duplicate CSV/TSV column names instead of dropping values - #987

Open
Jun-shisheng wants to merge 1 commit into
simonw:mainfrom
Jun-shisheng:fix/duplicate-csv-headers
Open

Jun-shisheng wants to merge 1 commit into
simonw:mainfrom
Jun-shisheng:fix/duplicate-csv-headers

Conversation

@Jun-shisheng

@Jun-shisheng Jun-shisheng commented Dec 2, 2026 •

Copy link
Copy Markdown

Fixes #986.

CSV/TSV files with duplicate column names were accepted and lost data silently.

insert --csv / --tsv built rows with dict(zip(headers, row)), so the last value for a repeated header won. A file like:

name,name
dog,cat

created a single name column containing cat, and exited 0. sqlite-utils memory had the same problem because csv.DictReader also keeps only the last duplicate.

Both paths now reject duplicate headers:

  • insert / upsert exit 1 with Error: Duplicate column names: name before creating the table.
  • rows_from_file() raises RowError when iterated, and memory turns that into the same CLI error.

Tests

Added regression tests for insert --csv, insert --tsv, rows_from_file() CSV/TSV, and memory. Full suite passes:

python -m pytest -q
# 1635 passed, 17 skipped

📚 Documentation preview 📚: https://sqlite-utils--987.org.readthedocs.build/en/987/

suirindo commented Dec 3, 2026

Copy link
Copy Markdown

Should the SQLite import path also catch headers that differ only in ASCII case? At 7e34d89, the patched CSV helper rejects Name,Name, but yields two distinct keys for Name,name. Creating an in-memory SQLite table from those two keys then raises OperationalError: duplicate column name: name. A check at the SQLite import boundary could give the same clear error without changing the standalone CSV reader's behavior. AI-assisted review; I ran the reader helper plus SQLite, not the full CLI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

insert --csv and memory silently drop values when column names are duplicated

2 participants