Re: passing list values to an executemany cursor
Menno <menno-jZ/TYErj1jVWk0Htik3J/[email protected]>
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
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