This is a discussion on LOAD DATA INFILE within the MySQL forums, part of the Database Server Software category; --> Hello folks, Is it possible to update a column using LOAD DATA INFILE, So the following is an example: ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hello folks, Is it possible to update a column using LOAD DATA INFILE, So the following is an example: LOAD DATA LOCAL INFILE 'c:/test.txt' INTO TABLE test FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (lname, fname, zip); Results: id | fname | lname | zip 1 | kurt | russell | 45678 2 | worth | tim | 45687 3 | ridd | sherly | 45698 Now, I would like to load a file into the test table to replace only the zip column with the following: LOAD DATA LOCAL INFILE 'c:/test.txt' REPLACE INTO TABLE test FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (zip); But the above query removes the current data and sets only the zip and removes id, fname, lname. I would like it to update the zip column only. Is it possible? Thank you, Dan |
| |||
| == Quote from dcruzjr ( dcruzjr@gmail.com)'s article > Hello folks, > Is it possible to update a column using LOAD DATA INFILE, So the > following is an example: > LOAD DATA LOCAL INFILE 'c:/test.txt' > INTO TABLE test > FIELDS TERMINATED BY ',' > LINES TERMINATED BY '\n' > (lname, fname, zip); > Results: > id | fname | lname | zip > 1 | kurt | russell | 45678 > 2 | worth | tim | 45687 > 3 | ridd | sherly | 45698 > Now, I would like to load a file into the test table to replace only > the zip column with the following: > LOAD DATA LOCAL INFILE 'c:/test.txt' > REPLACE INTO TABLE test > FIELDS TERMINATED BY ',' > LINES TERMINATED BY '\n' > (zip); > But the above query removes the current data and sets only the zip and > removes id, fname, lname. I would like it to update the zip column > only. Is it possible? > Thank you, > Dan how about this: LOAD DATA LOCAL INFILE 'c:/test.txt' REPLACE INTO TABLE test (id, @dummy, fname, @dummy, lname, @dummy, zip) FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'; -- POST BY: lark with PHP News Reader |
| ||||
| On 11 Jul, 13:22, lark <ham...@sbcglobal.net> wrote: > == Quote from dcruzjr ( dcru...@gmail.com)'s article > > > > > > > Hello folks, > > Is it possible to update a column using LOAD DATA INFILE, So the > > following is an example: > > LOAD DATA LOCAL INFILE 'c:/test.txt' > > INTO TABLE test > > FIELDS TERMINATED BY ',' > > LINES TERMINATED BY '\n' > > (lname, fname, zip); > > Results: > > id | fname | lname | zip > > 1 | kurt | russell | 45678 > > 2 | worth | tim | 45687 > > 3 | ridd | sherly | 45698 > > Now, I would like to load a file into the test table to replace only > > the zip column with the following: > > LOAD DATA LOCAL INFILE 'c:/test.txt' > > REPLACE INTO TABLE test > > FIELDS TERMINATED BY ',' > > LINES TERMINATED BY '\n' > > (zip); > > But the above query removes the current data and sets only the zip and > > removes id, fname, lname. I would like it to update the zip column > > only. Is it possible? > > Thank you, > > Dan > > how about this: > > LOAD DATA LOCAL INFILE 'c:/test.txt' > REPLACE INTO TABLE test (id, @dummy, fname, @dummy, lname, @dummy, zip) > FIELDS TERMINATED BY ',' > LINES TERMINATED BY '\n'; > > -- > POST BY: lark with PHP News Reader- Hide quoted text - > > - Show quoted text - So, he asks to replace only the zip (I'm assuming that the text file contains only the zip and the id, which I would hope was a primary key - but his statement about the id being removed sounds a bit wierd). Anyway, you come up with a solution that instead of just replacing the zip, replaces all the other fields too. Nice one Lark. |