Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Insert Multiple Records Using One Insert Statemen with MySQLdb module

Reply
Thread Tools

Insert Multiple Records Using One Insert Statemen with MySQLdb module

 
 
anton.ranieri.it@gmail.com
Guest
Posts: n/a
 
      12-06-2008
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
 
Reply With Quote
 
 
 
 
Albert Hopkins
Guest
Posts: n/a
 
      12-06-2008
On Sat, 2008-12-06 at 04:03 -0800, http://www.velocityreviews.com/forums/(E-Mail Removed) 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: MySQLdb insert fails on one table Sells, Fred Python 0 06-01-2007 05:16 PM
MySQLdb insert fails on one table Sells, Fred Python 0 06-01-2007 03:48 PM
Struts/JSP - How would one view multiple database records over severalpages instead of one? Geoff Winsor Java 3 01-29-2005 03:31 AM
Insert Multiple Records at a time based on checkbox selection Vijay Pathak via .NET 247 ASP .Net 0 09-22-2004 06:53 AM
Re: insert multiple records using asp.net Michael Ramey ASP .Net 0 01-30-2004 10:25 PM



Advertisments