updating db with csv

Discussion in 'Python' started by moishyyehuda@gmail.com, Jun 7, 2007.

  1. Guest

    #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.
     
    , Jun 7, 2007
    #1
    1. Advertising

  2. Tim Roberts Guest

    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,
    Providenza & Boekelheide, Inc.
     
    Tim Roberts, Jun 11, 2007
    #2
    1. Advertising

  3. On 11 Jun, 07:37, Tim Roberts <> 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,
    | 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.
     
    Captain Paralytic, Jun 11, 2007
    #3
  4. Tim Roberts Guest

    Captain Paralytic <> wrote:

    >On 11 Jun, 07:37, Tim Roberts <> 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,
    Providenza & Boekelheide, Inc.
     
    Tim Roberts, Jun 13, 2007
    #4
  5. On 13 Jun, 06:35, Tim Roberts <> wrote:
    > Captain Paralytic <> wrote:
    > >On 11 Jun, 07:37, Tim Roberts <> 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,
    > 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.
     
    Captain Paralytic, Jun 13, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michal Mikolajczyk
    Replies:
    0
    Views:
    694
    Michal Mikolajczyk
    Feb 13, 2004
  2. Skip Montanaro
    Replies:
    0
    Views:
    766
    Skip Montanaro
    Feb 13, 2004
  3. Tintin92
    Replies:
    1
    Views:
    1,808
    Andrew Thompson
    Feb 14, 2007
  4. jliu66
    Replies:
    0
    Views:
    562
    jliu66
    Oct 19, 2007
  5. news.rcn.com
    Replies:
    2
    Views:
    1,182
    Roedy Green
    Dec 10, 2007
Loading...

Share This Page