-
Notifications
You must be signed in to change notification settings - Fork 66
Open
Labels
Description
What happens?
Using a placeholder for the output file in a COPY TO statement fails if the file does not already exist. Since I get the same error via both Rust and Python, it might not belong in either duckdb-rs or duckdb-python.
(Is a function to SQL escape parameters available via the API?)
To Reproduce
This Python code with an output file name as a param:
import duckdb
conn = duckdb.connect()
inp = "input.ndjson"
out = "output.ndjson"
conn.execute("COPY (FROM read_json(?)) TO ? (FORMAT JSON)", [inp, out])fails with:
conn.execute("COPY (FROM read_json(?)) TO ? (FORMAT JSON)", [inp, out])
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_duckdb.IOException: IO Error: No files found that match the pattern "output.ndjson"
LINE 1: COPY (FROM read_json(?)) TO ? (FORMAT JSON)
^
Whereas incorporating the file name into the string works, and tmp.ndjson is created:
safe = out.replace("'", "''")
conn.execute(f"COPY (FROM read_json(?)) TO '{safe}' (FORMAT JSON)", [inp])It seems that having the output file as a placeholder almost works, but the fopen() mode is perhaps wrong.
OS:
MacOS
DuckDB Package Version:
1.5.0
Python Version:
3.13
Full Name:
James Gilbert
Affiliation:
Wellcome Sanger Institue
What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.
I have tested with a stable release
Did you include all relevant data sets for reproducing the issue?
Not applicable - the reproduction does not require a data set
Did you include all code required to reproduce the issue?
- Yes, I have
Did you include all relevant configuration to reproduce the issue?
- Yes, I have
Reactions are currently unavailable