Running queries against CSV files with SQLite

Costas

Administrator
Staff member
using sqlite3 executable (for windows download sqlite-tools)

Bash:
sqlite3 :memory: -cmd '.mode csv' -cmd '.import taxi.csv taxi' \
  'SELECT passenger_count, COUNT(*), AVG(total_amount) FROM taxi GROUP BY passenger_count'


under windows
Bash:
sqlite3 :memory: -cmd ".mode csv" -cmd ".import 'C:\test\20220215082921_CSV.txt' taxi" "SELECT passenger_count, COUNT(*), AVG(total_amount) FROM taxi GROUP BY passenger_count"

src - https://til.simonwillison.net/sqlite/one-line-csv-operations

more over Simon develop sqlite-utils and the new feature is Joining CSV and JSON data with an in-memory SQLite database
 
Top