dbcli / mycli

A Terminal Client for MySQL with AutoCompletion and Syntax Highlighting.
http://mycli.net
Other
11.39k stars 657 forks source link

Numeric values quoted in CSV output #1005

Open nachtkinder opened 2 years ago

nachtkinder commented 2 years ago

Hi,

When outputting results in CSV format using the --csv option results in numeric values become enclosed in double-quotes.

For example mycli ... --csv -e "select int_column, float_column, string_column from some_table limit 3" produces output:

"int_column","float_column","string_column"
"1","1.0","String 1"
"2","2.0","String 2"
"3","0.3","String 3"

Where, in order to preserve the numeric values' types, it should produce:

"int_column","float_column","string_column"
1,1.0,"String 1"
2,2.0,"String 2"
3,0.3,"String 3"

In order to produce CSV output from the official MySQL client I wrote a small filter in Python that would receive piped output from mysql and return CSV formatted output. The usage is mysql ... -e "query" | tocsv. I have tried it with mycli and it seems to work just fine; mycli ... --csv -e "select int_column, float_column, string_column from some_table limit 3" | tocsv produces the desired output. I have attached my script (renamed with additional ".txt" extension) for reference.

tocsv.py.txt

My filter uses pandas (https://pandas.pydata.org) which I use in a number of other scripts and so I can rely on it being installed where I need it. This may be too heavy a dependency for mycli. Perhaps it is just a matter of choosing another quoting strategy to fix the issue.

Hope this helps,

-- nachtkinder

greigm commented 3 months ago

Is there any progress on this one? It would be very useful.