At 17:17 -0500 2/23/04, David Perron wrote:
Thanks Garth.  Actually Im trying to change the delimiter in the context of
running a sql file from the command line - so in this case, I would want to
change from tab to csv

mysql -h db#-reports.adz -u readonly -p < script.sql > output.csv ads12

You can't do it. You'll need to produce your datafile some other way, or else postprocess the output from mysql to transform it from tab-delimited to CSV format. Here's a short fragment from MySQL Cookbook on the subject:

% mysql db_name < inputfile  \
    | sed -e 's/"/""/g' -e 's/TAB/","/g' -e 's/^/"/' -e 's/$/"/' > outputfile

That's  fairly  cryptic,  to say the least.  You can achieve
the same result with other languages that may be  easier  to
read.   Here's  a short Perl script that does the same thing
as the sed command (it converts tab-delimited input  to  CSV
output), and includes comments to document how it works:

     #! /usr/bin/perl -w
     while (<>)              # read next input line
     {
         s/"/""/g;           # double any quotes within column values
         s/\t/","/g;         # put `","' between column values
         s/^/"/;             # add `"' before the first value
         s/$/"/;             # add `"' after the last value
         print;              # print the result
     }
     exit (0);

If you name the script csv.pl, you can use it like this:

% mysql db_name < inputfile | csv.pl > outputfile



-----Original Message----- From: Garth Webb [mailto:[EMAIL PROTECTED] Sent: Monday, February 23, 2004 5:01 PM To: [EMAIL PROTECTED] Subject: Re: Changing default delimiter


I'm not sure in what context you want to change the delimiter, but here's the doc page on the LOAD DATA command which shows how to terminate (a.k.a. delimit) fields with different characters:

http://www.mysql.com/doc/en/LOAD_DATA.html

On Mon, 2004-02-23 at 13:53, David Perron wrote:
 Greetings -
 Been scouring the docs for this all day and I come up with nothing for
 'delimiter' - Id like to change the default delimiter in mysql to
something
 other than tab.
 Is there a command to do this, and what are the options?

Thank you!

> David


--
Paul DuBois, MySQL Documentation Team
Madison, Wisconsin, USA
MySQL AB, www.mysql.com

MySQL Users Conference: April 14-16, 2004
http://www.mysql.com/uc2004/

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to