updating db with csv

Tim Roberts timr at probo.com
Mon Jun 11 02:37:12 EDT 2007


moishyyehuda at gmail.com wrote:
>
>#1 If any one familiar with godaddy hosting. They have apparently have
>a hosing server i.e.(scripts, html files etc.), and a server for
>databases. How can I import from my script,  with a csv. if the db is
>on a different server than the script server.

What does this have to do with either Python or MySQL?

When you connect to the database, you have to specify a hostname.  As long
as you provide the right one, it doesn't matter where your script runs.

>#2 I would like to update and insert with the same csv file. Is there
>a way to tell the database for some lines to update, and for some
>lines to insert.

Not in standard SQL.  MySQL supports a REPLACE extension that does an
UPDATE if the key already exists, and an INSERT if it does not.  There is
also an extension clause to the INSERT statement called "ON DUPLICATE KEY
UPDATE xxx" that might do what you want.
-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the Python-list mailing list