4 ms·
LOAD DATA INFILE can't conditionally create a foreign record, but you can certainly format a value on insert by using the SET clause, for example: LOAD DAT
by jeremysmyth 12y ago
LOAD DATA INFILE can't conditionally create a foreign record, but you can certainly format a value on insert by using the SET clause, for example:
LOAD DATA INFILE 'people.txt'
INTO TABLE Person (@first, @last, date_of_birth)
SET full_name = CONCAT(LEFT(@first, 1), '. ', @last);
You can even do funky stuff like lookups:
LOAD DATA INFILE 'projects.txt'
INTO TABLE Projects(@first, @last, project)
SET person_id =
(SELECT id FROM people
WHERE name = CONCAT(@first, ' ', @last) LIMIT 1);
- michaelmior 12y agoCool! I wasn't aware you could do that sort of thing with LOAD DATA INFILE. Thanks :)
- blowski 12y agoI didn't know that either - thanks for sharing.