I am using SQLite and I can't import this csv file for some reason. I ran cmd first then entered SQLite.
my input in cmd:
cd C:\Users\Fries\Desktop\SQLite
sqlite3
.mode csv
.import C:\Users\Fries\Desktop\city.csv cities
.schema cities
I am using this tutorial. http://www.sqlitetutorial.net/sqlite-import-csv/
for some reason I can't open the csv
I am new to dbms and sqlite seems to be a super simple one
Going by the feedback in the error message, it looks like the backslashes need to be escaped. I would first try this:
sqlite> .import C:/Users/Fries/Desktop/city.csv
The following might also work, using escaped backslashes:
sqlite> .import C:\\Users\\Fries\\Desktop\\city.csv
Related
I have a csv file with ; separator. I would like to convert it into .db. I follow advice here: https://www.sqlite.org/cli.html#section_8
In my Ubuntu terminal I use:
sqlite3 ex1
Then I try:
.mode list
.separator ";"
.import odberatel.csv odberatel
.save odberatel.db
But When I look on the odberatel.db in Db Browser for SQLite it seems that is not separated correctly:
What do I do wrong, please?
From the same sqlite doc:
Note that it is important to set the "mode" to "csv" before running the ".import" command.
I'm trying to add rows from a CSV file to an existing table.
In Mac Terminal, I start sqlite3:
sqlite> .open database.db
sqlite> .import test.csv table
.
.
.
test.csv:43200: expected 22 columns but found 1 - filling the rest with NULL
sqlite>
Notice there are 43200 rows in the csv file. The file itself has 22 comma separated columns, but sqlite only thinks there is 1 column.
According to the finds of Cgaters and the official documentation of SQLite:
Use the ".import" command to import CSV (comma separated value) data into an SQLite table. The ".import" command takes two arguments which are the name of the disk file from which CSV data is to be read and the name of the SQLite table into which the CSV data is to be inserted.
Note that it is important to set the "mode" to "csv" before running the ".import" command. This is necessary to prevent the command-line shell from trying to interpret the input file text as some other format.
Example:
sqlite> .mode csv
sqlite> .import C:/work/somedata.csv tab1
I have a text file which contains an sqlite statment where I want to dump it into .sql format but not able to excute it. Any help would be appreciated. My file is stored on desktop as verbali.txt and when i go to command prompt and to specific sqlite folder and run it just open the text file .
.mode insert
.header on
.out file.sql
select select Id ,CompanyId ,DateTime ,Serial ,DeviceId ,AgentAId ,GpsAddress ,Targa ,CommonRoadDescription ,RoadCivicNumber ,VehicleBrandDescription ,VehicleModelDescription ,VerbaliVehicleTypeDescription ,CommonColorVehicleDescription ,VerbaliRuleOneCode ,VerbaliRuleOneDescription ,VerbaliRuleOnePoints ,VerbaliClosedNoteDescription ,Points ,VerbaliMissedNotificationDescription ,MissedNotificationNote ,StatementNote from VerbaliData
Pipe the file to sqlite3, in command prompt:
sqlite3 yourdatabase.db <path\to\verbali.txt
where sqlite3 is the sqlite3.exe command line tool.
I want the filename to be something like this top_queries_June.csv. Is it possible to do that in sqlite?
sqlite>.output (top_Queries + Select date('now')).csv
I run this batch file to create a file with the top queries.
Batch file:
sqlite3 mydb.db ".read x.sql"
x.sql:
.headers ON
.mode csv
.output Top_Queries + <current month>.csv
select * from query;
.quit
As #CL. already pointed out the sqlite3 command line utility is not flexible enough to do this. You appear to be using some kind of shell to execute sqlite3. Most shells support a feature called "here document" and the sqlite3 utility supports reading commands from a pipe. Using these you can inline the x.sql file into your shell script. In a POSIX compatible shell your code could look like this:
DATE=`date -I`
sqlite3 mydb.db <<EOF
.headers ON
.mode csv
.output Top_Queries${DATE}.csv
select * from query;
EOF
I have two databases that are created in a bash file, let's call them 1.sqlite and 2.sqlite. I'd like to combine them into a new database (3.sqlite). Is there a command in bash that'll do that?
Edit:
The answer that sputnick gave me got me on the right track. But I had to rearrange it to be:
sqlite3 1.sqlite .dump > tempdb.sqlite
Yes, try the following shell code:
sqlite3 .dump 1.sqlite > dump
sqlite3 .dump 2.sqlite >> dump
sqlite3 3.sqlite < dump
But take care of table collisions if they have the same names.