Live data from Hacker News

Q: Run SQL Directly on CSV Files

harelba.github.io

91–100 of 102 posts

Re: Q: Run SQL Directly on CSV Files

#91
post #55

Earlier quoted context omitted.

Usability suffers, if you can't type the delimiters easily.

I can’t stand it when I’m banging out a CSV by hand and have to manually escape the field and record separators. Happens all the time.

I use TSV for that reason. Most of the time you don't need to escape anything. And from code you need to escape/unescape only 4 chars. \t \n \NULL and \\.

Re: Q: Run SQL Directly on CSV Files

#92
post #90
post #71

Earlier quoted context omitted.

They don’t really get used IMO because if you’re storing ASCII or Unicode text, you have to be prepared for those characters to be in your data. And if you’re storing binary data, delimiters don’t really cut it in the first place.

No it's fine. Just base64 encode the binary data. It's common and streams, or you can capture and convert the entire field at once if you need to seek around in the binary data. https://en.wikipedia.org/wiki/Base64

That only works if the thing consuming your CSV can be configured to decode whatever encoding you picked. Uploading CSVs of data to various SQL servers is an example case where that is often not possible.

Re: Q: Run SQL Directly on CSV Files

#94
post #71

Earlier quoted context omitted.

They don’t really get used IMO because if you’re storing ASCII or Unicode text, you have to be prepared for those characters to be in your data. And if you’re storing binary data, delimiters don’t really cut it in the first place.

also they cannot be found in keyboards, if you need to write CSV by hand

Can't be found, but you can enter them by hand by holding down alt while entering the ASCII code on the numeric keypad. I wonder if they'll survive posting a comment: 28∟ 29↔ 30▲ 31▼ Edit: looks like they do survive. Hmmm... Now I wonder about extended ASCII. └┐│└└╚╦╝

Re: Q: Run SQL Directly on CSV Files

#95

csvkit includes csvsql, which does this. I’ve used it and liked it. https://csvkit.readthedocs.io/en/1.0.3/tutorial/3_power_tool...

Came here to tell about csvkit and the csvsql that comes with it. Highly recommended. It is one of the first things I install on a new system.

Re: Q: Run SQL Directly on CSV Files

#96
post #94

Earlier quoted context omitted.

also they cannot be found in keyboards, if you need to write CSV by hand

Can't be found, but you can enter them by hand by holding down alt while entering the ASCII code on the numeric keypad. I wonder if they'll survive posting a comment: 28∟ 29↔ 30▲ 31▼ Edit: looks like they do survive. Hmmm... Now I wonder about extended ASCII. └┐│└└╚╦╝

Also, you can leverage the ISO/IEC 2022 extension and represent them with Caret Notation. Note: recommend an escaping mechanism depending on data. REF: https://en.wikipedia.org/wiki/C0_and_C1_control_codes#C0_(AS... An editor such as vim or pager like 'less' will display them. You can also 'cat -v' a file.

Re: Q: Run SQL Directly on CSV Files

#97

Earlier quoted context omitted.

Text::CSV_XS is my goto module for csv just use that and whack it into MySQL postgress would be my advice.

nah sqlite is what you want when you want a step up from CSV.

Well all I want to do is ingest some Google analytics and combine it with the data from SEmRush

Re: Q: Run SQL Directly on CSV Files

#99
post #33

Real-world CSV files generally contain some or all of the following horrors: - some strings enclosed in speechmarks, but some not - empty fields - speechmarks within strings - commas within strings - carriage returns within strings How does Q do up against a CSV file with those traits?

For those reasons I much prefer tab-delimited files. Does anyone know if Q supports that?

q supports any kind of input and output delimiter (-d and -D respectively).

harelba (creator of q)

Re: Q: Run SQL Directly on CSV Files

#100
post #32

Real-world CSV files generally contain some or all of the following horrors: - some strings enclosed in speechmarks, but some not - empty fields - speechmarks within strings - commas within strings - carriage returns within strings How does Q do up against a CSV file with those traits?

More interesting: any kind of delimiter, including chars from utf8 and windows-1252, and you need to detect encoding too. And CSV embedded in CSV, a result of flattening an XML source. And fixed width files, not CSV but where you see CSV you may need to support. And let's not get into date parsing or other typed data, and type inference over sample files.

Hi, q's creator here,

Any kind of input/output delimiter is supported (-d and -D ), and also multiple encodings (-e ). Also, q performs automatic type inference over the actual data.

Encoding autodetection and fixed width files are not supported though.

Post reply on HN