sqlite3 :memory: -cmd '.mode csv' ... It should be a war crime for programs in 2022 to use non-UNIX/non-GNU style command line options. Add it to the Rome Statute's Article 7 list of crimes against humanity. Full blown tribunal at The Hague presided over by the international criminal court. Punishable by having to use Visual Basic 3.0 for all programming for the rest of their life.
Would :memory: even parse in some shells?
One-liner for running queries against CSV files with SQLite
91–100 of 131 posts
Re: One-liner for running queries against CSV files with SQLite
#92Here is the way to pretty-print the same result with mlr:
mlr --icsv --opprint --barred stats1 -a count,mean -f total_amount -g passenger_count then sort -f passenger_count taxi.csv
Re: One-liner for running queries against CSV files with SQLite
#93Earlier quoted context omitted.
I added a feature last year that lets you do this as a one-step process - "sqlite-utils memory": https://simonwillison.net/2021/Jun/19/sqlite-utils-memory/
Those steps still exist though surely, just managed by the one command. If you're querying via SQLite you have to ingest first.
Re: One-liner for running queries against CSV files with SQLite
#94If you need to query against multiple CSVs, e.g. using joins, you could use QHS: https://github.com/itchyny/qhs
[0] https://csvkit.readthedocs.io/en/latest/scripts/csvsql.html
Re: One-liner for running queries against CSV files with SQLite
#95Can somebody post the equivalent in Windows cmd?
Re: One-liner for running queries against CSV files with SQLite
#96I’ve been doing this. But I hate it. CSVs need to die. They’re terrible data formats. But here we are. And SQLlite makes things amazing.
Re: One-liner for running queries against CSV files with SQLite
#97I like using q for querying CSVs on the command line: https://github.com/harelba/q
Re: One-liner for running queries against CSV files with SQLite
#98I’ve been doing this. But I hate it. CSVs need to die. They’re terrible data formats. But here we are. And SQLlite makes things amazing.
I'm willing to bet CSV will still be around in 200 years. It's ugly, but exceedingly effective.
Re: One-liner for running queries against CSV files with SQLite
#99Earlier quoted context omitted.
And in fact there is a CSV virtual table available from SQLite but it's not built in the normal client: https://www.sqlite.org/csv.html It really should be, as the code is tiny and this functionality is not overly exotic.
In my experience [1], the CSV virtual table was really slow. Doing some analysis on a 1,291 MB file, a query took 24.7 seconds using the virtual table vs 3.4 seconds if you imported the file first. The CSV virtual table source code is a good pedagogical tool for teaching how to build a virtual table, though. [1]: https://cldellow.com/2018/06/22/sqlite-parquet-vtable.html
Re: One-liner for running queries against CSV files with SQLite
#100Earlier quoted context omitted.
Clickhouse-local is incredible. It does the best of any similar tool I've benchmarked. But the reason I took it out of the linked benchmarks in OP's post is because it's 2+GB. That's a massive binary. It's the whole server. I'm not sure you want to be distributing this all over the place in general. It's just not in the same category IMO. Disclaimer: I build another tool that does similar things.
It is shipped with debug info and symbol tables just in case. Without debug info, it will be 350 MB, and compressed can fit in 50 MB: https://github.com/ClickHouse/ClickHouse/issues/29378 It is definitely a worth improvement.