mycli
mycli copied to clipboard
Numeric values quoted in CSV output
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.
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