SQLite Forum

Additional Delimiter Support for the CSV Virtual Table Module
Login
>Request to allow the CSV Virtual Table module (https://www.sqlite.org/csv.html) to support additional delimiters

<i>If you are using the CSV extension, the approach detailed below may or may not work; I have been unable to compile the extension and therefore I am unable to test.</i>

<i>On the other hand</i>, if you are using <b>.import</b>, (that is, the CLI) you can use <b>any</b> delimiter using the technique illustrated below (Iam using Windows).

<b>Step 1:</b> Edit your CSV file using any text editor and add the following <b>as the first line in your file</b>; here I am using \| as the delimiter.

> sep = \|


<b>Step 2:</b> My file is SAMPLE.CSV; examine your file to ensure that the first line is inserted correctly.

```
sqlite> .shell type 'E:\CSV\sample.csv'
sep=!
FirstName|Surname|Factor
ajay|askoolum|100.23
askoolum|ajay|23.10
```


<i>Note the first line.</i> - you can specify any <b>arbitrary</b> single character delimiter. The second line contains column names and is followed by two rows of data.

<b>Step 3:</b> Drop the target table (if it exists)

```
sqlite> drop table if exists tblMySample;
```
<b>Step 4:</b> Read the CSV which contains columns delimited by \|

```
sqlite> .import --skip 1 E:/CSV/sample.csv tblMySample
```
<b>Step 5:</b> Examine your table

```
sqlite> select * from tblMySample;
FirstName  Surname   Factor
---------  --------  ------
ajay       askoolum  100.23
askoolum   ajay      23.10
```
For the sake of completeness, I repeat the steps above using ^ as the delimiter: here's my session:

```
sqlite> .shell type 'E:\CSV\sample.csv'
sep=^
FirstName|Surname|Factor
ajay|askoolum|100.23
askoolum|ajay|23.10
sqlite> drop table if exists tblMySample;
sqlite> .import --skip 1 E:/CSV/sample.csv tblMySample
sqlite> select * from tblMySample;
FirstName  Surname   Factor
---------  --------  ------
ajay       askoolum  100.23
askoolum   ajay      23.10
```