473,323 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Export/import of column names with space

Hello,

I am using MySQL 4.0.
Say that I have a table named "mytable" having a column "ID" and a
column "test columnname".

When dumping:

mysqldump --opt DATABASE -uUSER -hHOST -pPASS > myfile.txt

it gives someting like:

CREATE TABLE mytable(ID int(11) NOT NULL, test columnname text NOT
NULL);

Then I use the mysql command to import myfile.txt in another database:

mysql DATABASE -uUSER -hHOST -pPASS < myfile.txt

but it fails with:

"ERROR 1064 at line 1: You have an error in your SQL syntax. Check the
manual that corresponds to your MySQL server version for the right
syntax to use near 'test columnname text NOT NULL)' at line 1"

Obviously, the mysql command can't handle column names with spaces. Is
this a bug? I would say so - mysqldump should put the column names
between quotes or so (alternatively, mysql shouldn't allow spaces in
column names).

My problem is that I have to work with these columns as they are.
They're also referred to from a lot of queries in the API's. Any
possible workarounds?

Thanks
Bart
Jul 20 '05 #1
2 2255
Bart Van der Donck wrote:
I am using MySQL 4.0.
Say that I have a table named "mytable" having a column "ID" and a
column "test columnname".

When dumping:

mysqldump --opt DATABASE -uUSER -hHOST -pPASS > myfile.txt

it gives someting like:

CREATE TABLE mytable(ID int(11) NOT NULL, test columnname text NOT
NULL);

Then I use the mysql command to import myfile.txt in another database:

mysql DATABASE -uUSER -hHOST -pPASS < myfile.txt

but it fails with:

"ERROR 1064 at line 1: You have an error in your SQL syntax. Check the
manual that corresponds to your MySQL server version for the right
syntax to use near 'test columnname text NOT NULL)' at line 1"

Obviously, the mysql command can't handle column names with spaces. Is
this a bug? I would say so - mysqldump should put the column names
between quotes or so (alternatively, mysql shouldn't allow spaces in
column names).

My problem is that I have to work with these columns as they are.
They're also referred to from a lot of queries in the API's. Any
possible workarounds?


Dump the data with the "-Q" / "--quote-names" flag. This puts backticks
around all table and column names and prevents this problem from happening.

eg: mysqldump --opt DATABASE -Q -uUSER -hHOST -pPASS > myfile.txt

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 20 '05 #2
Chris Hope wrote:
Dump the data with the "-Q" / "--quote-names" flag. This puts backticks
around all table and column names and prevents this problem from happening.

eg: mysqldump --opt DATABASE -Q -uUSER -hHOST -pPASS > myfile.txt


Thanks Chris, that's what I was looking for.
However, illogical mysql behaviour I think...
When one can create column names with spaces by default, mysqldump
should also use backticks by default. (Or the opposite, not allowing
spaces and then not using backticks in dump)

Anyway, it works fine now.

Bart
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: R.A. Joemman | last post by:
Hi, We are migrating a database from Oracle 8.1.7.0.0 to Oracle 9.2.0.1.0 on AIX. Export as follows: exp ${user}/${pwd} compress=n file=${file} log=${log} owner=${schema} grants=y indexes=y...
2
by: Bart Van der Donck | last post by:
Hello, I am using MySQL 4.0. Say that I have a table named "mytable" having a column "ID" and a column "test columnname". When dumping: mysqldump --opt DATABASE -uUSER -hHOST -pPASS >...
205
by: Jeremy Siek | last post by:
CALL FOR PAPERS/PARTICIPATION C++, Boost, and the Future of C++ Libraries Workshop at OOPSLA October 24-28, 2004 Vancouver, British Columbia, Canada http://tinyurl.com/4n5pf Submissions
1
by: Janne Ruuttunen | last post by:
Hello DB2 people, I'm having problems exporting >= 250000 lobs to IXF files with the LOBSINFILE option, using a legacy DB2 2.1 system on Win NT. If I don't specify a path for the lobs,...
1
by: kk | last post by:
Hi, I am trying to set up scheduled export in DB2. DB2 seems to be missing the ability to export column names for CSV. Apparently 'method N' is only for ixf and wsf files. I have a C# and/or...
2
by: Siu | last post by:
Hi, I use the following code to export and import a file Excel from resp. into a Web page with the following code: //EXPORT Response.Clear(); Response.Buffer = true; Response.ContentType =...
8
by: Taffman | last post by:
I've searched this goup for an answer to this, there are many discussions that come close but non that I can find that actually addresses this particular problem. I'm exporting queries to Excel....
13
by: mjf | last post by:
Hello, Is there a way to export the data from some tables, along with their corresponding column names? I know I can use "export" command to export the data from a table to a DEL file (the users...
3
by: Wayne | last post by:
I'm trying to automate the export of a query to a text file using code. If I export the query manually I get the exact result that I want i.e. If I select the query then choose File/Export from...
0
by: kkshansid | last post by:
i cannot export my sql server database to msaccess database which i usually did successfully 3weeks ago pls help me to find the error so that i can correct it in future error is - Validating...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.