how to generate a csv file in linux from sql query when data may contain a comma?

Chris2019-01-10T23:57:34Z

Apparently the 2017 spec says to wrap every value that contains line breaks, double quotes or commas in double quotes, and to escape double quotes by using two double quotes.

So three values like this:
abc
def, ghi
"hello"

is supposed to be stored like this:

abc,"def, ghi","""hello"""

Programming languages usually have libraries to deal with this though.

Daniel B2019-01-10T20:22:02Z

You can put double quotes around the value of any field that may contain a comma.

Anonymous2019-01-10T20:01:50Z

Then you'll have to use an alternative format, such as a semi-colon separated variable, or a tab-separated, etc. Whichever type is least likely to occur within the field itself.