Gossamer Forum
Home : Products : Gossamer Links : Discussions :

How To Insert just SOME fields from File

Quote Reply
How To Insert just SOME fields from File
Hi:

In my install, I often will work on 100's of new entries, upload them as a txt file, and then put them into the database with Load Infile, like thus:

LOAD DATA INFILE 'Arr.txt' REPLACE INTO TABLE `Links` FIELDS TERMINATED BY '|' ESCAPED BY '\\' LINES TERMINATED BY '\n' IGNORE 0 LINES

Works great.

Now I want to add some new data to existing entries. I could download all the data, and then re-upload with the above comant... but why should I if I am only adding an image link? Why not just get the ID, Issue, and put the image with it, and insert that?

So I tried:

LOAD DATA INFILE 'Arr.txt' REPLACE INTO TABLE `Links` (ID, Issue, Image) FIELDS TERMINATED BY '|' ESCAPED BY '\\' LINES TERMINATED BY '\n' IGNORE 0 LINES

which did, in fact, insert all three fields appropriately... however, it DELETED all the other info! Luckily, I was practicing on a non-needed row, and only one, so I did not kill anything important!

So, my question is, how can I load an infile and just insert SOME data, w/o deleting all the rest? Or should I give it up, and d/l and insert ALL the data?

dave

Big Cartoon DataBase
Big Comic Book DataBase
Quote Reply
Re: [carfac] How To Insert just SOME fields from File In reply to
You tried my Data_Import plugin? I'm assuming the file is in pipe/comma seperated format?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] How To Insert just SOME fields from File In reply to
Hi Andy:

No, I have not- I will go take a look. I assume it will update SOME fields based on ID? Yes, pipe-delimited.

I found a work around- kind of involved, but here gores.

First B/U your links table- structure only is fine, lets say to Links_bu.

To the above Load Infile, but to Links_bu and NOT Links

Then update the fields you want updated from Links_bu to Links, thus:

UPDATE Links_bu,Links SET Links.Image = Links_bu.Image WHERE Links.ID=Links_bu.ID;

dave

Big Cartoon DataBase
Big Comic Book DataBase