[DB-SIG] PySQL/insert a list of tuples....
Denis Cartier Millon
Denis.CM@Wanadoo.fr
Fri, 23 Aug 2002 10:24:43 +0200
--------------080608070500060807000702
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by cat686.snm.agriculture.gouv.fr id KAA32114
YES BUT two probl=E8mes :
1: the "%" : %s,%i,..... % <list og params> (format like in C) ignore=20
the none (Python) null (SQL),
2: this solution needs to now the numbers and the types of parameters...
before i use the module pg.py (module postgresql) and pg.inserttable=20
(<table>,<liste o tuples>) : inserttable (Mytable,x) but this solution
don't insert the none value.
with <?>
cur.executemany ("insert into Mytable values (?,?,?)", list of params) =20
(example in LINUX JOURNAL
the mappage is OK by the the dbapi
but i must know the numbers of params.
is the syntaxe :
cur.executemany ("insert into Mytable values (?,?,?)", x)
# where x is a list of tuples is OK ???
# if this is OK i win because i can build the string "insert into=20
Mytable values(?,?,?....)
Marcos S=E1nchez Provencio a =E9crit:
>El jue, 22-08-2002 a las 15:10, Denis Cartier Millon escribi=F3:
> =20
>
>>I want insert a sequence of sequence (list og tuples) in a table ,
>>(x comme from the script select * from Mytable with an fethchall)
>>
>>and the script is :
>>cur=3Dconn.cursor()
>>cur.executemany("insert into Mytable values (%s)",x) # is there a=20
>>solution thanks.....
>>
>> =20
>>
>Is there a problem?
>
>But seriously, you have to give as many %s as column values you want
>inserted in your sql=20
>
>cur.executemany("insert into Mytable (col1,col2,col3) values
>(%s,%s,%s)",x)
>
>
>_______________________________________________
>DB-SIG maillist - DB-SIG@python.org
>http://mail.python.org/mailman/listinfo/db-sig
>
> =20
>
--------------080608070500060807000702
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<title></title>
</head>
<body>
YES BUT two problèmes :<br>
<br>
1: the "%" : %s,%i,..... % <list og params> (format like in C) ignore
the none (Python) null (SQL),<br>
2: this solution needs to now the numbers and the types of parameters...<br>
<br>
before i use the module pg.py (module postgresql) and pg.inserttable (<table>,<liste
o tuples>) : inserttable (Mytable,x) but this solution<br>
don't insert the none value.<br>
<br>
<br>
with <?><br>
<br>
cur.executemany ("insert into Mytable values (?,?,?)", list of params)
(example in LINUX JOURNAL<br>
the mappage is OK by the the dbapi <br>
but i must know the numbers of params.<br>
<br>
is the syntaxe :<br>
<br>
cur.executemany ("insert into Mytable values (?,?,?)", x)<br>
# where x is a list of tuples is OK ???<br>
# if this is OK i win because i can build the string "insert into Mytable
values(?,?,?....)<br>
<br>
<br>
Marcos Sánchez Provencio a écrit:<br>
<blockquote type="cite"
cite="mid1030034137.1199.5.camel@renata.macondo.pri">
<pre wrap="">El jue, 22-08-2002 a las 15:10, Denis Cartier Millon escribió:
</pre>
<blockquote type="cite">
<pre wrap="">I want insert a sequence of sequence (list og tuples) in a table ,
(x comme from the script select * from Mytable with an fethchall)
and the script is :
cur=conn.cursor()
cur.executemany("insert into Mytable values (%s)",x) # is there a
solution thanks.....
</pre>
</blockquote>
<pre wrap=""><!---->Is there a problem?
But seriously, you have to give as many %s as column values you want
inserted in your sql
cur.executemany("insert into Mytable (col1,col2,col3) values
(%s,%s,%s)",x)
_______________________________________________
DB-SIG maillist - <a class="moz-txt-link-abbreviated" href="mailto:DB-SIG@python.org">DB-SIG@python.org</a>
<a class="moz-txt-link-freetext" href="http://mail.python.org/mailman/listinfo/db-sig">http://mail.python.org/mailman/listinfo/db-sig</a>
</pre>
</blockquote>
<br>
</body>
</html>
--------------080608070500060807000702--