2

Here is my code:

conn = psycopg2.connect("dbname='test1' user='postgres' host='localhost' password='123'")
cur = conn.cursor()
query = "INSERT INTO product_info (product_name) VALUES (%s);"
data = ("ss")
cur.execute(query, data)

conn.commit()

I am not sure why i get the error: not all arguments converted during string formatting, I can't figure out my syntax error

1 Answer 1

1

What's happening is that the string ss is being considered two parameters. If you make data a tuple you get around this problem. All that needs to change is a comma.

conn = psycopg2.connect("dbname='test1' user='postgres' host='localhost' password='123'")
cur = conn.cursor()
query = "INSERT INTO product_info (product_name) VALUES (%s);"
data = ("ss",) # make this a tuple!
cur.execute(query, data)
conn.commit()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.