Skip to content

Commit c8c261a

Browse files
authored
import -csv
1 parent a3d2e18 commit c8c261a

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

sqlite/one-line-csv-operations.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ I figured out how to run a SQL query directly against a CSV file using the `sqli
77

88
This uses the special `:memory:` filename to open an in-memory database. Then it uses two `-cmd` options to turn on CSV mode and import the `taxi.csv` file into a table called `taxi`. Then it runs the SQL query.
99

10+
Instead of setting the mode with `.mode` you can use `.import -csv` like this (thanks, [Mark Lawrence](https://sqlite.org/forum/forumpost/ad9d1a8f3e9feb8b)):
11+
12+
sqlite3 :memory: -cmd '.import -csv taxi.csv taxi' \
13+
'SELECT passenger_count, COUNT(*), AVG(total_amount) FROM taxi GROUP BY passenger_count'
14+
1015
You can get `taxi.csv` by downloading the compressed file from [here](https://github.com/multiprocessio/dsq/blob/43e72ff1d2c871082fed0ae401dd59e2ff9f6cfe/testdata/taxi.csv.7z) and running:
1116

1217
7z e -aos taxi.csv.7z

0 commit comments

Comments
 (0)