Fix DuckDB bulk_insert failing when quoted CSV cells fall outside sniffer sample#64
Merged
martinv13 merged 3 commits intoJun 17, 2026
Merged
Conversation
…ffer sample (cre-dev#62) DuckDB's read_csv sniffer only examines the first ~20 480 rows; if none are quoted, it sets quote=(empty) and then errors on any later quoted cell with a column-count mismatch. Passing quote='"' explicitly bypasses auto-detection. Adds a regression test that inserts 25 000 plain rows followed by one row whose value contains a comma (triggering csv.writer quoting). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Makes the RFC 4180 doubling behaviour explicit rather than relying on DuckDB defaulting escape to the same char as quote. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #62.
read_csvsniffer examines only the first ~20 480 rows as its sample. If no quoted cells appear in that sample, it setsquote=(empty)— meaning it treats"as an ordinary character.join-transformed columns produce a value containing a comma (e.g."val,ue",other), Python'scsv.writerwraps the whole cell in outer quotes. Any such cell beyond row ~20 480 would cause a column-count mismatch and anInvalid Input Error.quote='"'explicitly toread_csvinDuckDBDialect.bulk_insert, bypassing auto-detection entirely.Test plan
test_duckdb_bulk_insert_quoted_csv_field_after_large_unquoted_sampleinserts 25 000 plain rows followed by one row whoselabelcontains a comma; verifies all rows are read back correctly.test_bulk_insert.pytests still pass.TZ="Europe/Paris" DB_STRING="duckdb:///:memory:" python -m pytest🤖 Generated with Claude Code