Charles
Charles

Reputation: 57

sqlite3 can't import .csv file

I'm very new to DQL and sqlite. I've created a very basic database and am trying to import data from a .csv file. I watched a tutorial and have entered the following code:

.import countries.csv countries

This gives the following error:

Error: cannot open "countries.csv"

I'm sure im over looking something easy here. countries.csv is a file I made in excel and saved as a .csv. In Text Editor it opens as a normal comma seperated values file

Upvotes: 1

Views: 12284

Answers (4)

own_universe
own_universe

Reputation: 1

Oh! It took me few hours to solve the problem and it nearly drove me mad! I had saved the csv file in a folder while I didn't change the terminal into it. I used cs50ide and after I typed in 'cd folder/' and then tryed again, it worked. Hope this can help u.

Upvotes: -1

apbmpls
apbmpls

Reputation: 41

You need to escape the backslash by using doubles. I've had success using two backslashes in the path when doing this on Windows.

Try this out:

sqlite> .import "C:\\working\\tmp\\data.txt" tablename

Upvotes: 4

Papasmile
Papasmile

Reputation: 634

I tried to use ~/ on mac, but needed to use path eg /Users/me/.

Upvotes: 1

Charles
Charles

Reputation: 57

For anyone with the same problem - any path that contains spaces needs to use quotation marks

Upvotes: 3

Related Questions