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.
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:Where, in order to preserve the numeric values' types, it should produce:
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 ismysql ... -e "query" | tocsv
. I have tried it withmycli
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