PDA

View Full Version : Converting .CSV to MySql database


adi501
07-18-2008, 09:26 PM
Hello everybody.

I have a problem while converting .csv formatted file to Mysql database.

I have used the following statement in order to convert

LOAD DATA LOCAL INFILE 'D:/US-zip-codes.csv' IGNORE INTO TABLE oz.zip_geo_info FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY "" LINES TERMINATED BY '\r\n' (field1,field2,..........................,field19)

In my table FIELD1 is the primary key.
The above statement worked and it has put the values from the .csv to mysql table. But it has excluded all the rows which have duplicate values for the primiray key.

I want all the duplicate columns. How can i get all the values?
Thanks in advance.

CFMaBiSmAd
07-18-2008, 09:36 PM
You have specified the IGNORE keyword in the query.

The REPLACE and IGNORE keywords control handling of input rows that duplicate existing rows on unique key values:

If you specify REPLACE, input rows replace existing rows. In other words, rows that have the same value for a primary key or unique index as an existing row. See Section 12.2.6, “REPLACE Syntax”.

If you specify IGNORE, input rows that duplicate an existing row on a unique key value are skipped. If you do not specify either option, the behavior depends on whether the LOCAL keyword is specified. Without LOCAL, an error occurs when a duplicate key value is found, and the rest of the text file is ignored. With LOCAL, the default behavior is the same as if IGNORE is specified; this is because the server has no way to stop transmission of the file in the middle of the operation.