Skip to content

Instantly share code, notes, and snippets.

@joshes
Created June 21, 2022 18:05
Show Gist options
  • Save joshes/14cef0e87e1001ab87181d7f0e2bdd51 to your computer and use it in GitHub Desktop.
Save joshes/14cef0e87e1001ab87181d7f0e2bdd51 to your computer and use it in GitHub Desktop.

CSV SQLite

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

sqlite3 \
  :memory: \
  -cmd '.mode csv' \
  -cmd '.import taxi.csv taxi' \
  'SELECT passenger_count, COUNT(*), AVG(total_amount) FROM taxi GROUP BY passenger_count'
  • Add -cmd '.mode column' to output in columns instead
  • Add -cmd '.mode markdown' to get a Markdown table
  • Show all modes sqlite3 -cmd '.help mode'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment