Insert Multiple Records Using One Insert Statemen with MySQLdb module
Albert Hopkins
marduk at letterboxes.org
Sat Dec 6 07:47:27 EST 2008
On Sat, 2008-12-06 at 04:03 -0800, anton.ranieri.it at gmail.com 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
More information about the Python-list
mailing list