updating db with csv

This is a discussion on updating db with csv within the MySQL Database forums, part of the Database Forums category; #1 If any one familiar with godaddy hosting. They have apparently have a hosing server i.e.(scripts, html files ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-07-2007
moishyyehuda@gmail.com
 
Posts: n/a
Default updating db with csv

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

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

Reply With Quote
  #2 (permalink)  
Old 06-11-2007
Tim Roberts
 
Posts: n/a
Default Re: updating db with csv

moishyyehuda@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@probo.com
Providenza & Boekelheide, Inc.
Reply With Quote
  #3 (permalink)  
Old 06-11-2007
Captain Paralytic
 
Posts: n/a
Default Re: updating db with csv

On 11 Jun, 07:37, Tim Roberts <t...@probo.com> wrote:
| 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, t...@probo.com
| Providenza & Boekelheide, Inc.

No Tim, that is not correct. the REPLACE extension does not do an
update, it does a replace. It delets the old record and inserts a new
one. The INSERT...ON DUPLICATE KEY UPDATE... does an update. So a
REPLACE will remove all existing field values not referenced in the
statement, whilst an INSERT...ON DUPLICATE KEY UPDATE... will preserve
them. Also REPLACE will make a TIMESTAMP column which has a DEFAULT
CURRENT_TIMESTAMP setting work like one which has ON UPDATE
CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP setting.

Reply With Quote
  #4 (permalink)  
Old 06-13-2007
Tim Roberts
 
Posts: n/a
Default Re: updating db with csv

Captain Paralytic <paul_lautman@yahoo.com> wrote:

>On 11 Jun, 07:37, Tim Roberts <t...@probo.com> wrote:
>| 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.
>
>No Tim, that is not correct. the REPLACE extension does not do an
>update, it does a replace. It delets the old record and inserts a new
>one. The INSERT...ON DUPLICATE KEY UPDATE... does an update. So a
>REPLACE will remove all existing field values not referenced in the
>statement, whilst an INSERT...ON DUPLICATE KEY UPDATE... will preserve
>them. Also REPLACE will make a TIMESTAMP column which has a DEFAULT
>CURRENT_TIMESTAMP setting work like one which has ON UPDATE
>CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP setting.


Thanks for the correction; that's an important difference. I'm a Postgres
guy; if I had noticed this was cross-posted to c.d.mysql as well as
comp.lang.python, I probably would have kept quiet.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
Reply With Quote
  #5 (permalink)  
Old 06-13-2007
Captain Paralytic
 
Posts: n/a
Default Re: updating db with csv

On 13 Jun, 06:35, Tim Roberts <t...@probo.com> wrote:
> Captain Paralytic <paul_laut...@yahoo.com> wrote:
> >On 11 Jun, 07:37, Tim Roberts <t...@probo.com> wrote:
> >| 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.

>
> >No Tim, that is not correct. the REPLACE extension does not do an
> >update, it does a replace. It delets the old record and inserts a new
> >one. The INSERT...ON DUPLICATE KEY UPDATE... does an update. So a
> >REPLACE will remove all existing field values not referenced in the
> >statement, whilst an INSERT...ON DUPLICATE KEY UPDATE... will preserve
> >them. Also REPLACE will make a TIMESTAMP column which has a DEFAULT
> >CURRENT_TIMESTAMP setting work like one which has ON UPDATE
> >CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP setting.

>
> Thanks for the correction; that's an important difference. I'm a Postgres
> guy; if I had noticed this was cross-posted to c.d.mysql as well as
> comp.lang.python, I probably would have kept quiet.
> --
> Tim Roberts, t...@probo.com
> Providenza & Boekelheide, Inc.


But then you wouldn't have learned about this important difference. I
too learn a lot when I give what I think is a correct answer and then
have someone else explain what really happens.

The wonder of usenet.

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:25 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0