Re: passing list values to an executemany cursor

Peter Tittmann <[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
Thanks all for your help. Slowly, I learn....

I was able to insert the list values using Menno's suggested approach 
(below).

Totally grateful.

Peter

Menno wrote:
> Peter Tittmann wrote:
>>
>> insert_st='INSERT INTO pmh VALUES ('+frcs_o+')'
>> cur.executemany(insert_st)
>>
>
> The immediate problem is that you are trying to add a list (frcs_o) to 
> a string. This is causing the traceback you're seeing. This is nothing 
> to do with psycopg.
>
> That said, it appears that you misunderstand how executemany works. It 
> takes 2 arguments: a statement and a sequence of sets of variables to 
> apply to the statement. It runs the statement multiple times, once for 
> each set of variables.
>
> In your case it looks like you only want to insert one row so 
> executemany isn't really needed.
>
> You probably want something like:
>
>    placeholders = ', '.join(['%s'] * len(frcs_names))
>    insert_st='INSERT INTO pmh VALUES (%s)' % placeholders
>    cur.execute(insert_st, frcs_o)
>
> HTH,
> Menno
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.