CSV driver

Read and write delimited text with the built-in CSV driver.

Configure the connection

Use driver="csv" and set url to a file path relative to the ETL file. Set encoding=UTF-8 for portable results. Without it, the driver uses the system charset.

The default delimiter is a comma and the default quote character is a double quote. Set separator and quote on each connection to match the file. An empty quote= disables quoting, so use it only when fields can be written unambiguously without quotes.

By default, an input query reads column names from the first row. Set headers=false for headerless input and access fields by position with $1, $2, and so on. Write output headers explicitly as a script row. Set eol to change the output line ending from LF.

Convert CSV to semicolon-delimited output

Save this input as customers.csv.

id,name
1,"Garcia, Ana"

Save the ETL file beside it as copy-csv.etl.xml and run scriptella.sh copy-csv.etl.xml.

<?xml version="1.0"?>
<!DOCTYPE etl SYSTEM "http://scriptella.org/dtd/etl.dtd">
<etl>
    <connection id="input" driver="csv" url="customers.csv">
        encoding=UTF-8
    </connection>
    <connection id="output" driver="csv" url="customers-out.csv">
        encoding=UTF-8
        separator=;
    </connection>
    <script connection-id="output">id,name</script>
    <query connection-id="input">
        <script connection-id="output">$id,$name</script>
    </query>
</etl>

The new customers-out.csv contains these rows.

"id";"name"
"1";"Garcia, Ana"

Query and output syntax

A query with no filter text reads all data rows. To filter, use comma-separated case-insensitive regular expressions. Always use commas inside query and script bodies, even when a connection reads or writes another delimiter. CSV fields are text by default. Set null_string to map an explicit file token to and from null.

See the CSV driver Javadoc for the complete property list, the CSV-to-PostgreSQL guide for a database import, and benchmarks for measured CSV import performance.