Data Import & Export

View Source

DuckdbEx exposes read functions on DuckdbEx and DuckdbEx.Connection and export functions on DuckdbEx.Relation.

Read CSV

rel = DuckdbEx.read_csv("data.csv", header: true, sep: ",")
{:ok, rows} = DuckdbEx.Relation.fetch_all(rel)

Read JSON

rel = DuckdbEx.read_json("data.json")

Read Parquet

rel = DuckdbEx.read_parquet("data.parquet")

Export CSV

rel = DuckdbEx.Connection.sql(conn, "SELECT * FROM users")
DuckdbEx.Relation.to_csv(rel, "users.csv", header: true)

Export Parquet

DuckdbEx.Relation.to_parquet(rel, "users.parquet", compression: "zstd")

Partitioned Output

DuckdbEx.Relation.to_parquet(rel, "out_dir",
  partition_by: ["country"],
  filename_pattern: "chunk_{i}"
)

Notes

  • Options are passed to DuckDB table functions and COPY where possible.
  • Some advanced options (DataFrame/Arrow integration) are not available in the CLI backend; use SQL or export files as a workaround.