How can I generate an output in CSV format from a database query?

Luigi Viggiano

CSV stands for "Comma Separated Values", so just keep any record and separe each field with a comma and each record with a newline (' '). You'll have a perfect CSV file, easy readable by any program supporting this simple format.

It's very common to put as first line the names of fields.