I want to save a list of strings to a postgresDB with psycopg2 in python 3.9.5. When I store the data as a python list and send it to the database with execute I get the following error.
TypeError: not all arguments converted during string formatting My code looks like this
import psycopg2
dbName = "testDB"
with psycopg2.connect(user="user", password="password") as conn:
cur = conn.cursor()
alon = (1,2,3)
cur.execute("Insert into " + dbName + "(url,arrayInp) VALUES ('test_url',%s)",alon)
This error does not occur when I "create" the list inside the execute statement like this
import psycopg2
dbName = "testDB"
with psycopg2.connect(user="user", password="password") as conn:
cur = conn.cursor()
cur.mogrify("Insert into " + dbName + "(url,arrayInp) VALUES ('test_url','{{1},{2},{3}}')")
Whenever I try to use mogrify to send commands to the DB it works without errors, but nothing is inserted into the DB