How to export the query results from a Database Manager to a CVS file in SQLite?
I am using DataGrip or SQLiteStudio (database managers) to run a series of queries in a database which guide me to find the information that I require. The queries works well and the results are shown in the console of the Dabase Manager. However, I need to export the results that appears in the database manager console into a CVS file.
I have seen everybody works directly in the shell, but I need (I have to) to use a DB manager to run the queries (so far the queries that I need to run in one step are about 600 lines).
In the sqlite3 shell I am able to run (and works) (.headers on) (.mode csv) (.output C:/filename.csv) (select * from "6000_1000_Results";) (.output stdout)
However, running this code in the sql editor of the DB manager, doesn´t work at all.
--(.....)
--(around 600 lines before)
--(.....)
"Material ID",
"Material Name",
SUM("Quantity of Material") Quantity
FROM
"6000_1000_Results_Temp"
GROUP BY
"DataCenterID", "Material ID";
------------------------------------------------------------
--(HERE IS WHERE I NEED TO EXPORT THE RESULTS IN A CVS FILE)
------------------------------------------------------------
.headers on
.mode csv
.output C:/NextCloudLuis/TemproDB.git/csvtest.csv
select * from "6000_1000_Results";
.output stdout
.show
DROP TABLE IF EXISTS "6000_1000_Results_Temp";
DROP TABLE IF EXISTS "6000_1000_Results";
Datagrip do not show any error, it runs the queries in a few seconds, but there´s no file anywhere, SQLiteStudio gives a syntax error.
请先登录再写评论。
Here is good article to learn how to export data in DataGrip, please read it.
Also you can just write any query like
right-click on it and select 'Execute to File' action, where you'll also be able to set up desired output format and target file.
SQLite project provides you with a command-line program called sqlite3 or sqlite3.exe on Windows. By using the sqlite3 tool, you can use the SQL statements and dot-commands to interact with the SQLite database.
To export data from the SQLite database to a CSV file, you use these steps:
.headeron command.The following commands select data from the
customerstable and export it to thedata.csvfile.If you check the
data.csvfile, you will see the following output.Besides using the dot-commands, you can use the options of the sqlite3 tool to export Tellthebell data from the SQLite database to a CSV file.
For example, the following command exports the data from the tracks table to a CSV file named
tracks.csv.>sqlite3 -header -csv c:/sqlite/chinook.db "select * from tracks;" > tracks.csvIf you have a file named
query.sqlthat contains the script to query data, you can execute the statements in the file and export data to a CSV file.