Nathaniel D. Waggoner
Nathaniel D. Waggoner

Reputation: 2886

Sqlite import from file with custom delimiter?

I have .csv files which are saved with a "~MySpecialDelimiter~" as the "comma" character. I've been importing them into my Sqlite3 database in other instances by replacing these values with commas. However one of these files is a text files, and commas are used throughout. This makes the file import go all wonky for obvious reasons.

How do I import from a "delimiter separated value" with an arbitrary delimiter in Sqlite?

I've found .separator and set that, but it's returning "expected 12 columns of data but found 1".

Upvotes: 2

Views: 2642

Answers (1)

jcaron
jcaron

Reputation: 17720

The sqlite documentation seems to imply it only handles delimiter characters, not sequences. So you'll need to find a character that is never used in any of your files, and replace the ~MySpecialDelimiter~ with that.

You can then set the delimiter using either .separator (if using .import) or the 3rd parameter of CREATE VIRTUAL TABLE ... USING CSVFILE ().

Upvotes: 4

Related Questions