?
Solved

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

Posted on 2009-05-11
3
Medium Priority
?
678 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 1000 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

765 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