Unix Technical Forum

LOAD DATA INFILE

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: ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 10:12 AM
dcruzjr@gmail.com
 
Posts: n/a
Default LOAD DATA INFILE

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 10:12 AM
lark
 
Posts: n/a
Default Re: LOAD DATA INFILE

== 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 10:12 AM
Captain Paralytic
 
Posts: n/a
Default Re: LOAD DATA INFILE

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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:13 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com