A word of advice: if there is any chance that a column (e.g. text) contains an embedded newline, you will be much better off outputting the data in simple xml, instead of CSV. This works very well with Excel for import. I just did a simple program for this recently. Susan Ryan Suarez <ryan.suarez@sheridanc. To: pgsql-general@xxxxxxxxxxxxxx on.ca> cc: Sent by: Subject: [GENERAL] Exporting postgres query to CSV |-------------------| pgsql-general-owner@pos | [ ] Expand Groups | tgresql.org |-------------------| 05/09/2006 07:58 AM Greetings, I am running postgres 7.4.7 on debian sarge. I need to run an SQL query and store the results in a file. The format needs to be comma separated values (CSV), so I can import this later in Excel. Any ideas on how to accomplish this? much appreciated, Ryan ---------------------------(end of broadcast)--------------------------- TIP 6: explain analyze is your friend ---------------------------------------------------------------------------------------------- Simply protected storage solutions ensure that your information is automatically safe, readily available and always there, visit us at http://www.overlandstorage.com ----------------------------------------------------------------------------------------------