Solved

When importing from CSV, why is MySQL raising a 'Data truncated' warning?

Posted on 2009-05-11
3
639 Views
Last Modified: 2012-05-06
When running a simple SQL command to import some CSV data, I'm receiving warnings on a particular column on seemingly random rows:
Warning (Code 1265): Data truncated for column 'SubGroupNum' at row 2
Warning (Code 1265): Data truncated for column 'SubGroupNum' at row 3
Warning (Code 1265): Data truncated for column 'SubGroupNum' at row 5
Warning (Code 1265): Data truncated for column 'SubGroupNum' at row 6
Warning (Code 1265): Data truncated for column 'SubGroupNum' at row 8

Here is the schema of the DB:
+-------------+--------------+------+-----+---------+-------+
| Field       | Type         | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| IdxId       | double       | NO   |     | NULL    |       |
| YrGrpId     | double       | NO   |     | NULL    |       |
| GroupNum    | double       | NO   |     | NULL    |       |
| LineNum     | int(11)      | NO   |     | NULL    |       |
| LogicalMod  | int(11)      | YES  |     | NULL    |       |
| Application | varchar(255) | YES  |     | NULL    |       |
| SubGroupNum | double       | YES  |     | NULL    |       |
| SubCategory | varchar(2)   | YES  |     | NULL    |       |
| PTypeNum    | char(3)      | YES  |     | NULL    |       |
| IntchNum    | char(5)      | YES  |     | NULL    |       |
| AlphaExt    | char(2)      | YES  |     | NULL    |       |
| LRFlag      | char(1)      | YES  |     | NULL    |       |
+-------------+--------------+------+-----+---------+-------+

Any insight as to what I need to change?
load data local infile 'Idx_App.txt' into table `Idx_App`

fields terminated by ','

enclosed by ''''

lines terminated by '\r\n'

(IdxId, YrGrpId, GroupNum, LineNum, LogicalMod, Application, SubGroupNum, SubCategory, PTypeNum, IntchNum, AlphaExt, LRFlag)

;

Open in new window

Idx-App.txt
0
Comment
Question by:fluffyx
3 Comments
 
LVL 6

Expert Comment

by:bull_rider
ID: 24361078
What I observed is if teh subgroupname is not provided that row fails. Can you check the datatype or may be the column in the database is accepting NULL or blank values or not?
0
 
LVL 6

Accepted Solution

by:
BALMUKUND KESHAV earned 250 total points
ID: 24361406
problem is where is subgroup has no data, and its showing like ,,,
if you have checked your subgroup fields type accepting null or 0,then if its varchar type then try to change your txt fields format like this
fields enclosed with " " sepereated with , and ensure where is no data it shows ""
then use this command

 load data local infile 'Idx_App.txt' into table `Idx_App`
fields terminated by ","
enclosed by ""
lines terminated by '\r\n'
(IdxId, YrGrpId, GroupNum, LineNum, LogicalMod, Application, SubGroupNum, SubCategory, PTypeNum, IntchNum, AlphaExt, LRFlag)

bm keshav

 
0
 

Author Closing Comment

by:fluffyx
ID: 31580376
That's causing it! Now comes the challenge of modifying the 80MB TXT file :-).
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now