Dumb question but your clarification at the start makes me ask ... can you use SQL to query a CSV file?? Is the answer basically “in theory yes but in practice no”?
In his clarification, he mentioned “relational database”. Think of that like a word document or an Excel file. A Word doc is something you create with your data, but you need a special piece of software to read or edit it — in this case, Microsoft Word. A database is similarly a thing that is created to contain and organize your data and that requires a special piece of software to read and edit — a database engine like Microsoft SQL Server 2017 or Oracle. Those programs also store your data in special formats designed to specifically enable certain types of queries and updates to be much faster (and generally lots of other features as well).
Those products are what take SQL queries and efficiently find the data you want. Other people have written software that can take SQL and query CSV instead, but since they just have the CSV to use to access the data instead of the specially optimized formats, you don’t get the faster reads and other features.
It's been done. A quick Google came up with http://harelba.github.io/q/ which offers a SQL interface to CSV files. It won't have the performance of a proper relational database because of the lack of indexing etc.
Most database engines allow importing CSV. To toy around with it, it's just two lines in SQLite till you can go SELECT * FROM myStuff WHERE distance>12.
It's notably faster than a "dumb" python script reading the csv line-by-line - including the time needed for import. Even without adding indices, typical queries willl be faster, because the data is already laid out and "type tagged" for access and iteration.
Advantage over the method mentioned by /u/splenetic: you can add indices etc. when things get slow. Downside: you need to re-import when the csv changes.
3
u/de_rats_2004_crzy Dec 06 '19
Dumb question but your clarification at the start makes me ask ... can you use SQL to query a CSV file?? Is the answer basically “in theory yes but in practice no”?