mmzeeman / educkdb

DuckDB NIF for Erlang

Repository from Github https://github.commmzeeman/educkdbRepository from Github https://github.commmzeeman/educkdb

Load CSV in a Table

Zabrane opened this issue · comments

@mmzeeman would it be possible to load a CSV from disk into DuckDB table?
The DuckDB webpage has such an example.

Note that there is an issue with loading duckdb extensions. Duckdb loads these extensions on the fly, but I noticed the extensions are not always available.

It looks like the CSV functionality is not a duckdb extension, and it should work. I did not test it though.

I will try to push a core duckdb lib update this weekend, maybe that will help.

@mmzeeman amazing. I will wait for the new push. Many thanks.

I updated duckdb to v0.4.0 and did a quick test in the shell. I could extract data from a css file. Let me know if it works for you too.

7> {ok, R} = educkdb:query(C, "SELECT * FROM 'test.csv';").
{ok,#Ref<0.1512156153.963510292.189268>}  
8> educkdb:extract_result(R).
[#{data => [{1988,1,1},{1988,1,2},{1988,1,3}],
   name => <<"FlightDate">>,type => date},
 #{data => [<<"AA">>,<<"AA">>,<<"AA">>],
   name => <<"UniqueCarrier">>,type => varchar},
 #{data =>
       [<<"New York, NY">>,<<"New York, NY">>,<<"New York, NY">>],
   name => <<"OriginCityName">>,type => varchar},
 #{data =>
       [<<"Los Angeles, CA">>,<<"Los Angeles, CA">>,
        <<"Los Angeles, CA">>],
   name => <<"DestCityName">>,type => varchar}]

Example from here: https://duckdb.org/docs/data/csv

@mmzeeman Working perfectly. Thanks for this great addition.