[DB-SIG] PySQL/insert a list of tuples....
Denis Cartier Millon
Denis.CM@Wanadoo.fr
Mon, 26 Aug 2002 10:17:01 +0200
--------------010302060006040409020708
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 KAA08458
i can't execute this synthaxe with the module pgdb.py
cur.execut("insert into Mytable values (?,?,?)", list of params in tuples=
)
why?=20
i try an other module "psycopg.so"
Marcos S=E1nchez Provencio a =E9crit:
>El vie, 23-08-2002 a las 10:24, Denis Cartier Millon escribi=F3:
> =20
>
>>YES BUT two probl=E8mes :
>>
>>1: the "%" : %s,%i,..... % <list og params> (format like in C) ignor=
e=20
>>the none (Python) null (SQL),
>>2: this solution needs to now the numbers and the types of parameters.=
..
>> =20
>>
>
>You must not merge the string with %, but pass the parameters to the
>function
>
>executemany('sql blablabla ' , (list of parameters in tuples) )
>I believe you may use %s for every parameter, whatever its type.
>
>
> =20
>
>>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(?,?,?....)
>>
>>
>> =20
>>
>
>I believe that is the solution.
>
> =20
>
>>Marcos S=E1nchez Provencio a =E9crit:
>>
>> =20
>>
>>>El jue, 22-08-2002 a las 15:10, Denis Cartier Millon escribi=F3:
>>>=20
>>>
>>> =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
>>>>
>>>> =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
>>>
>>> =20
>>>
>
>
>
>_______________________________________________
>DB-SIG maillist - DB-SIG@python.org
>http://mail.python.org/mailman/listinfo/db-sig
>
> =20
>
--------------010302060006040409020708
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
<pre wrap=""></pre>
<pre wrap="">i can't execute this synthaxe with the module pgdb.py
cur.execut("insert into Mytable values (?,?,?)", list of params in tuples)
why?
i try an other module "psycopg.so"</pre>
<br>
Marcos Sánchez Provencio a écrit:<br>
<blockquote type="cite"
cite="mid1030183982.1716.54.camel@renata.macondo.pri">
<pre wrap="">El vie, 23-08-2002 a las 10:24, Denis Cartier Millon escribió:
</pre>
<blockquote type="cite">
<pre wrap="">YES BUT two problèmes :
1: the "%" : %s,%i,..... % <list og params> (format like in C) ignore
the none (Python) null (SQL),
2: this solution needs to now the numbers and the types of parameters...
</pre>
</blockquote>
<pre wrap=""><!---->
You must not merge the string with %, but pass the parameters to the
function
<tt>executemany('sql blablabla ' , (list of parameters in tuples) )</tt>
I believe you may use %s for every parameter, whatever its type.
</pre>
<blockquote type="cite">
<pre wrap="">before i use the module pg.py (module postgresql) and pg.inserttable
(<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)
(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
Mytable values(?,?,?....)
</pre>
</blockquote>
<pre wrap=""><!---->
I believe that is the solution.
</pre>
<blockquote type="cite">
<pre wrap="">Marcos Sánchez Provencio a écrit:
</pre>
<blockquote type="cite">
<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>
</blockquote>
<pre wrap=""><!---->
_______________________________________________
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>
--------------010302060006040409020708--