Error when using changing mode to csv - sqlite

I am trying to import data from a csv file.
According to this , I should use .mode csv first. But when I enter that command, I get this error:
mode should be on of: column html insert line list
Why is this so ?
Google didn't help me much and I'm new to this.

You had probably entered on the SQLite shell using sqlite. Try to use sqlite3 to enter on the shell. There you will have the .mode csv.

I entered the shell with sqlite3 and got the same error when I tried to switch modes. I found out the problem was dumber then sqlite vs. sqlite3, I am new to this so newbie error lol
sqlite> .mode column;   will give the error mentioned ^
sqlite> .mode column  without the ; won't
you can check if the mode actually switched by just running .mode and it will tell you what mode it is on

Related

First column of sqlite table throwing error: no such column

This seems odd to me and violates my previous experience with SQLite. I have a trivial database with one table and 3 columns. When I query the first column I get 'Error: no such column: Name'. The other columns work fine. Log below. There must be something ridiculously basic that I am missing. My sleazy work-around is to add a dummy first column, at which point querying on 'Name' works fine, but that is pretty unsatisfactory. Running on a Mac mini (M1, 2020), macOS Monterey Version 12.5.1.
bash-3.2$ head Names/nameTest1.csv
Name,Gender,Count
James,M,5304407
John,M,5260831
Robert,M,4970386
...
bash-3.2$ sqlite3 test1.db
SQLite version 3.19.3 2017-06-08 14:26:16
Enter ".help" for usage hints.
sqlite> .mode csv
sqlite> .separator ','
sqlite> .import Names/nameTest1.csv testtable1
sqlite> .schema
.schema
CREATE TABLE testtable1(
"Name" TEXT,
"Gender" TEXT,
"Count" TEXT
);
sqlite> select * from testtable1 where Count='5304407';
James,M,5304407
sqlite> select * from testtable1 where Name='James';
Error: no such column: Name
sqlite> .quit
.quit
Your CSV file has the BOM field. It does not correspond to a printable character, so you do not see it, but SQLite fails to strip it and includes it as the the prefix of your Name field. This is a known issue, but recent versions of SQLite should handle it properly. You might be using an older version. Either upgrade your SQLite or strip the BOM code before importing.

sqlite3 .import failing to create table

I have seen other posts and tried the answers but it still will not create the table for me.
I simply want to import a .tab file into a new sqlite3 table on the fly.
I have tried .mode csv with a .separator '\t' and .mode tabs
I have the following command and error.
sqlite> .mode tabs
sqlite> .import /storage/mgymrek/gtex-estrs/revision/mastertables/Adipose-Subcutaneous_master.csv Temp1
Error: no such table: Temp1
I have also tried
sqlite3 -separator '\t' estr.db ".import Adipose-Subcutaneous_master.csv Temp1"
Error: no such table: Temp1
Please help!
To import a CSV file in SQLit3, set the mode to csv. If it's a tab-seperate-file, you could try importing the file as shown in: How to import a tsv file with SQLite3
sqlite> .mode csv
sqlite> .import /storage/mgymrek/gtex-estrs/revision/mastertables/Adipose-Subcutaneous_master.csv Temp1
As per this answer, if you have an older version of SQLite this will happen. I'm not sure in which version the automatic creation of a table was implemented, but from that post if you have SQLite 3.8.9 or newer it should automatically create the table, possibly a few versions before would also do that. If you have 3.7.17 or older it won't create the table, this is the version I have and it doesn't work (I arrived here investigating why). I don't know the versions in-between, but if you're there and it's not working for you I suggest you upgrade.

sqlite3 is not using end-of-line character when importing data

I have a tab-delimited file which I'm attempting to load into a table. The table has already been created and structured appropriately, the challenge is that SQLite3 is combining the last value on one row with the first value on the next row.
So for a file where the last line was SomeText, and the next line begins with 12345, the value imported is SomeText12345
Right now I'm using the following command:
.separator "\t";
.import MyFile.tsv MyTable
Any ideas how I can get the data to load while recognizing the end-of-line?
I noticed the same problem. I've always suspected it had to do with the last value in a tab-separated file being a TEXT type. A little stack-sniffing turned up this post wherein the second answer says:
There is actually a dedicated mode for importing tab separated files:
sqlite> .mode tabs
sqlite> .import MyFile.tsv MyTable

SQLITE 3.9.0, Windows 10 x64 - How to import a .csv from the command line shell?

I can do it using the GUI (not that hard) but I really would like do to it by sqlite command lines. I've googled it and have tried everything, however nothing seems to work. Please give me a hint on this! This is the last thing I've tried:
CREATE TABLE 'teste3' (
'Id' integer,
'Idade' integer,
'Sexo' text,
'Peso' integer
);
.separator ',';
.mode csv;
.import 'C:\Users\xxxx\Documents\Monografia\base_teste.csv' teste3
What I intended to do was to create a table ('teste3',done) and them "fill it" by importing a given .csv file. Instead, I keep getting this error message: "near ".": syntax error:". Then I tried to cut off the "." before separator, for example, but I got another error: "near "separator": syntax error:". I really don't know what to do. Thanks!
Dot commands like .mode and .import are not SQL statements; they are implemented by the sqlite3.exe command-line shell (which can be downloaded from the offical SQLite site).
The DB Browser for SQLite is an entirely independent tool. It does not implement these dot commands; you have to use the GUI instead.

Import .CSV files onto SQLite

I am having some problem in importing a .csv file into a sqlite table. My .csv file looks like this
Name,Age,,
Hamish,27,,
Praveen,27,,
There are no trailing spaces anywhere. I create a table in the SQLite db with the same schema, but when i run .import...it shows me an error saying "expected 2 columns of data but found 1". Probably something to do with the delimiter. Any ideas?
Make sure you specify the delimiter, and do so without quotes:
.separator ,

Resources