Skip to content

Honor overwrite=False for existing parquet/csv files - #642

Closed
00200200 wants to merge 2 commits into
duckdb:v2.0-cyanopterafrom
00200200:honor-overwrite-false-existing-file
Closed

00200200 wants to merge 2 commits into
duckdb:v2.0-cyanopterafrom
00200200:honor-overwrite-false-existing-file

Conversation

@00200200

@00200200 00200200 commented Sep 29, 2026 •

Copy link
Copy Markdown

Fixes #633. Fixes #156.

to_parquet(..., overwrite=False) and to_csv(..., overwrite=False) currently still replace an existing file. The flag is forwarded as COPY's overwrite_or_ignore, which only applies to partitioned output. For a single file, COPY writes to a tmp path and renames over the original, so the flag is a no-op.

When overwrite=False and the target already exists as a file, fail with the same IOException partitioned writes already use (Enable OVERWRITE option to overwrite the file). Default behaviour (omit overwrite) and overwrite=True are unchanged.

Tests in tests/fast/api/test_to_parquet.py and tests/fast/api/test_to_csv.py cover:

  • overwrite=False errors and leaves the original file
  • overwrite=True still replaces a single file

Validation after upstream sync

Merged v2.0-cyanoptera at b2d23c0ac04d5f778d020a044a54bafde0e20557, preserving the existing fix and tests. The include conflict was resolved by retaining file_system.hpp and accepting upstream removal of the obsolete Arrow collector include.

  • Built the native extension from source against the current DuckDB engine with CPython 3.13.4.
  • pytest tests/fast/api/test_to_csv.py tests/fast/api/test_to_parquet.py: 47 passed.
  • Ruff checks/formatting for both test files, clang-format for the helper, and git diff --check: passed.

COPY replaces a single file via a tmp rename, so overwrite=False had no
effect. Fail with the same IOException as partitioned writes instead of
silently replacing the file.
@evertlammerts

Copy link
Copy Markdown
Member

Thanks @00200200! With the upcoming 2.0 release there was too much that changed for a simple rebase, so I ported this in #668.

@00200200

Copy link
Copy Markdown
Author

Sounds good, thanks for porting it over!

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.

overwrite parameter in to_parquet does nothing overwrite parameter to relation.write_csv and write_parquet seems to do nothing

2 participants