TrueBlue10
TrueBlue10

Reputation: 418

Try to use CONCAT and SET in "LOAD INFILE"

I try to use the CONCAT function to create id for the table. I have the following code

LOAD DATA INFILE '/blah.txt'
    INTO TABLE blah
    CHARACTER SET utf8
    FIELDS TERMINATED BY '\t'
    LINES TERMINATED BY '\n'
    IGNORE 1 LINES
    (@a, @b, c, d, e, f)
    SET id=Concat(@a,'+',@b),a=@a,b=@b

I got the result

ERROR 1062 (23000): Duplicate entry '+' for key 'PRIMARY'

It means the values cannot pass to the variable. But I dont know Why.

Upvotes: 0

Views: 50

Answers (1)

Raj Srivastava
Raj Srivastava

Reputation: 785

One reason that I can think of is that there are empty lines in your txt file which will give @a & @b as null.

So, id will become '+'. If there are more than one empty lines, all will generate id = '+'. Thus, this error will come when MySQL tries to insert duplicate entry for primary key column, id.

Upvotes: 1

Related Questions