Search code examples
pythonexecutemany

mixing placeholders, executemany, and table names


I can iterate through a python object with te following code, however I would like to be able to use placeholders for the schema and table name, normally I do this with {}.{} ad the .format() methods, but how do you combine the two?

cur.executemany("INSERT INTO schema.table_name (x,y,z) "
                        "values (%s, %s, %s)", top_sample)

Solution

  • I'm not sure what the issue is. You can very well use format like this:

    cur.executemany("INSERT INTO {}.{} (x,y,z) values (%s, %s, %s)".format('hello', 'world'), top_sample)