MySQL Forums
Forum List  »  Newbie

Mysql INTO OUTFILE adding specials characters in the end of interger and decimal
Posted by: M Mansour
Date: March 26, 2015 09:29AM

I have strange behavior with SELECT INTO OUFILE and I didn't find an answer.

To resume I have a table like this :

CREATE TABLE `mytable` (
`id` int(11) NOT NULL auto_increment,
`field1` decimal(10,2) default NULL,
`field2` int(11) default NULL,
`field3` tinyint(4) default NULL,
PRIMARY KEY (`id`),
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

When I execute a query like this :

SELECT * INTO OUTFILE '/tmp/output.dat'
FIELDS TERMINATED BY '|'
OPTIONALLY ENCLOSED BY '\"'
ESCAPED BY ''
LINES TERMINATED BY '\n'
FROM mytable;

I obtain a result like this in the output.dat :

"12345678"|"20.00^@^@^@^@^@^@^@"|"1426513906^@"|"0^@^@^@"
"95863214"|"20.00^@^@^@^@^@^@^@"|"1426514075^@"|"1^@^@^@"

without ESCAPED BY :

SELECT * INTO OUTFILE '/tmp/output.dat'
FIELDS TERMINATED BY '|'
OPTIONALLY ENCLOSED BY '\"'
LINES TERMINATED BY '\n'
FROM mytable;

I have a result like this :

"12345678"|"20.00\0\0\0\0\0\0\0"|"1426513906\0"|"0\0\0\0"
"95863214"|"20.00\0\0\0\0\0\0\0"|"1426514075\0"|"1\0\0\0"

Mysql environment:

"protocol_version";"10"
"version";"5.0.67-community-log"
"version_comment";"MySQL Community Edition (GPL)"
"version_compile_machine";"x86_64"
"version_compile_os";"redhat-linux-gnu"

It seem like mysql try to fill with this special characters to have the size set in the structure of mytble. With TRIM I don't have this characters. But I want to know if it's normal to have this behavior only with integer and decimal or it's bug ? I want to know also if there are another solution to avoid using TRIM with each field ? Because I have a lot of queries more complex then this one.

Thank you for your help and the time that you took to read my post

Regards

Options: ReplyQuote


Subject
Written By
Posted
Mysql INTO OUTFILE adding specials characters in the end of interger and decimal
March 26, 2015 09:29AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.