Live data from Hacker News

One-liner for running queries against CSV files with SQLite

til.simonwillison.net

31–40 of 131 posts

Re: One-liner for running queries against CSV files with SQLite

#31
post #30
post #25

Earlier quoted context omitted.

SQL does not exactly implement relational algebra in its pure form. SQL implements a kind of set theory with relational elements and a bunch of practical features like pivots, window functions etc. Pandas does the same. Most data frame libraries like dplyr etc. implement a common set of useful constructs. There’s not much difference in expressiveness. LINQ Is another language around manipulating sets that was designe…

> There’s not much difference in expressiveness > However SQL is declarative Pick one :) the way I see it, if declarativeness is not a factor in assessing expressiveness, then expressiveness reduces to the uninteresting notion of Turing-equivalence.

Expressiveness and declarativeness are different things, no?

Are you talking about aesthetics? I’ve used SQL for 20 years and it’s elegant in parts but it also has warts. I talk about this elsewhere but SQL gets repetitive and requires multi layer CTEs to express certain simple aggregations.

Re: One-liner for running queries against CSV files with SQLite

#32
I am a data scientists. I have used a lot of tools/libraries to interact with data. SQLite is my favorite. It is hard to beat the syntax/grammar.

Also, when I use SQLite I do not output using column mode. I pipe to `tv` (tidy-viewer) to get a pretty output.

https://github.com/alexhallam/tv

transparency: I am the dev of this utility

Re: One-liner for running queries against CSV files with SQLite

#33
Using ClickHouse you can also process local files in one line using clickhouse-local command tool. And it will look a lot easier:

clickhouse local -q "SELECT passenger_count, COUNT(*), AVG(total_amount) FROM file(taxi.csv, 'CSVWithNames') GROUP BY passenger_count"

And ClickHouse supports a lot of different file formats both for import and export (you can see all of them here https://clickhouse.com/docs/en/interfaces/formats/).

There is an example of using clickhouse-local with taxi dataset mentioned in the post: https://colab.research.google.com/drive/1tiOUCjTnwUIFRxovpRX...

Re: One-liner for running queries against CSV files with SQLite

#38
Using DuckDB [1]:

  duckdb -c "SELECT passenger_count, COUNT(*), AVG(total_amount) FROM taxi.csv GROUP BY ALL"
DuckDB will automatically infer you are reading a CSV file from the extension, then automatically infer column names from the header, together with various CSV properties (data types, delimiter, quote type, etc). You don't even need to quote the table name as long as the file is in your current directory and the file name contains no special characters.

DuckDB uses the SQLite shell, so all of the commands that are mentioned in the article with SQLite will also work for DuckDB.

[1] https://github.com/duckdb/duckdb

Disclaimer: Developer of DuckDB

Re: One-liner for running queries against CSV files with SQLite

#39

Using DuckDB [1]: duckdb -c "SELECT passenger_count, COUNT(*), AVG(total_amount) FROM taxi.csv GROUP BY ALL" DuckDB will automatically infer you are reading a CSV file from the extension, then automatically infer column names from the header, together with various CSV properties (data types, delimiter, quote type, etc). You don't even need to quote the table name as long as the file is in your current directory and t…

How does the column data type inference work? I've run into that challenge myself in the past.

Re: One-liner for running queries against CSV files with SQLite

#40
Since many people are sharing one-liners with various tools...

OctoSQL[0]:

  octosql 'SELECT passenger_count, COUNT(*), AVG(total_amount) FROM taxi.csv GROUP BY passenger_count'
It also infers everything automatically and typechecks your query for errors. You can use it with csv, json, parquet but also Postgres, MySQL, etc. All in a single query!

[0]:https://github.com/cube2222/octosql

Disclaimer: author of OctoSQL

Post reply on HN