1

Looking for a bit more explanation from question asked here:

User Question

I've looked over the doc on MySQL however I'm looking for bit simpler terms as things aren't making sense on the site. I don't understand what:

LOAD DATA INFILE 'file.csv'
INTO TABLE t1
(column1, @dummy, column2, @dummy, column3, ...)
FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '"'
LINES TERMINATED BY '\r\n';`

the @dummy's are for?

If i have columns a,b,c and data for those how would I insert it limiting only those?

Thank you

Community
  • 1
  • 1
Petrogad
  • 4,405
  • 5
  • 38
  • 77

1 Answers1

3

It's in case the data in your CSV contains say 5 columns but you only want to use 3 of them for instance -- you use @dummy to specify that the column won't be in fact written into the table.

Liv
  • 6,006
  • 1
  • 22
  • 29
  • so by specifying column1, @dummy it won't write to it? – Petrogad May 10 '11 at 17:34
  • what it actually does it assigns the second column (after column1) to a variable called dummy -- rather than assign it to a column called dummy (which might not exist in your table). And by assigning it to a variable you are not going to use you effectively skip it. – Liv May 10 '11 at 17:35
  • 1
    No, imagine the data in your file has 5 columns : A,B,C,D,E -- and you are loading data into a table with 3 columns: column1, column2, column3 but you want column A from file written into the table in column1, column C into column2, and column E into column 3 -- so you won't use B and D. In that case you specify INTO TABLE t1( column1, @dummy, column2, @dummy, column3) - so you assign column B to a dummy variable and same for column D thus skipping them. – Liv May 10 '11 at 17:37