views:

48

answers:

1

I like mysqlimport, its fast and relatively easy to use (much faster then say, PHP or Python front-ends for importing > 20GB data files). However I'd like to do the following. I have a data file that looks like:

cat dog 7
Cat Dog 3
CaT DOG 1

with the fields as varchar, varchar, int

And I would like the final result to be stored as ['cat', 'dog', 11], i.e. I'd like the result to be inserted into the database if it doesn't exist and added (as in mathematical sense) to the existing one if it does while ignoring the case of the first two fields. I have a working solution in python, but I am looking for a native in mysql(import).

+1  A: 

For case sensitivity you could probably downgrade everything into lowercase (there's a function for that). If you want to concatenate it to previous entry, check MySQL string functions.

If you want to insert a record only if it does not exist, check REPLACE or INSERT ON DUPLICATE.

mindas
I don't want to concatenate the string - what I want is, if the previous entry exists I'd like to add the value of the third column to the the existing value in the table. (question has been edited to reflect this change).
Hooked
You might want to play with case-insensitive collation. For example, assuming your character set is latin1, your column definition would have 'varchar(x) character set latin1 collate latin1_general_cs'.When this is done, rest becomes easy with INSERT ON DUPLICATE.
mindas
The INSERT ON DUPLICATE combined with case-insensitive collation seems to be the way to go. While waiting for an answer I put them in as varbinary which in hindsight seems to be a bad idea as it loses the string functions built into MySQL.
Hooked