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

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

so by specifying column1, @dummy it won't write to it?
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.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.