Insert Multiple Records Using One Insert Statemen with MySQLdb module

Discussion in 'Python' started by anton.ranieri.it@gmail.com, Dec 6, 2008.

  1. Guest

    Hi,

    I'd like to insert Multiple Records Using One Insert Statement

    inserting one record using one insert statement works
    this is the example:

    import MySQLdb
    conn = MySQLdb.connect(host="localhost",.....)
    cursore = conn.cursor()
    cursore.execute('INSERT INTO frutta (nome, quantita) VALUES(%s, %s)',
    ('Pompelmi', 10)
    )

    but when I try to insert Multiple Records Using One Insert Statement
    in this way:

    cursore.execute('INSERT INTO frutta (nome, quantita) VALUES(%s, %s)',
    ('Pompelmi', 10),
    ('Pompelmi', 10),
    ('Pompelmi', 10)
    )

    it doesn't work!

    Antonella
     
    , Dec 6, 2008
    #1
    1. Advertising

  2. Re: Insert Multiple Records Using One Insert Statemen with MySQLdbmodule

    On Sat, 2008-12-06 at 04:03 -0800, wrote:
    > Hi,
    >
    > I'd like to insert Multiple Records Using One Insert Statement
    >
    > inserting one record using one insert statement works
    > this is the example:
    >
    > import MySQLdb
    > conn = MySQLdb.connect(host="localhost",.....)
    > cursore = conn.cursor()
    > cursore.execute('INSERT INTO frutta (nome, quantita) VALUES(%s, %s)',
    > ('Pompelmi', 10)
    > )
    >
    > but when I try to insert Multiple Records Using One Insert Statement
    > in this way:
    >
    > cursore.execute('INSERT INTO frutta (nome, quantita) VALUES(%s, %s)',
    > ('Pompelmi', 10),
    > ('Pompelmi', 10),
    > ('Pompelmi', 10)
    > )
    >
    > it doesn't work!


    You want to use the cursor's .executemany() method.

    > --
    > http://mail.python.org/mailman/listinfo/python-list
     
    Albert Hopkins, Dec 6, 2008
    #2
    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. Michael Ramey

    Re: insert multiple records using asp.net

    Michael Ramey, Jan 30, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    2,723
    Michael Ramey
    Jan 30, 2004
  2. Geoff Winsor
    Replies:
    3
    Views:
    6,753
    Ryan Stewart
    Jan 29, 2005
  3. loveNUNO
    Replies:
    2
    Views:
    967
    loveNUNO
    Nov 20, 2003
  4. Sells, Fred

    MySQLdb insert fails on one table

    Sells, Fred, Jun 1, 2007, in forum: Python
    Replies:
    0
    Views:
    279
    Sells, Fred
    Jun 1, 2007
  5. Sells, Fred

    RE: MySQLdb insert fails on one table

    Sells, Fred, Jun 1, 2007, in forum: Python
    Replies:
    0
    Views:
    391
    Sells, Fred
    Jun 1, 2007
Loading...

Share This Page