csvduckdb

read csv file delimited by file separator control character (FS/ASCII 28/UTF-8 0x1C) into duckdb using the CLI


Trying to read from a CSV file using file separator control character (FS/ASCII 28/UTF-8 0x1C) as delimiter into duckdb from the CLI:

CREATE TABLE some_table AS SELECT * FROM read_csv('/some/file.csv', delim='**<what goes here????>**');

Can someone please suggest the proper way to pass this field delimiter?

Thank you!


Solution

  • XFS=$(printf '\034')
    cat << EOF > test.csv
    header1${XFS}header2${XFS}header3
    value1${XFS}value2${XFS}value3
    test1${XFS}test2${XFS}test3
    EOF
    
    duckdb -c "FROM read_csv('test.csv', delim = E'\x1C', header = true)"
    ┌─────────┬─────────┬─────────┐
    │ header1 │ header2 │ header3 │
    │ varchar │ varchar │ varchar │
    ├─────────┼─────────┼─────────┤
    │ value1  │ value2  │ value3  │
    │ test1   │ test2   │ test3   │
    └─────────┴─────────┴─────────┘