0
`def copy_Stones(ipt, lhailstones):
    iptstr = str(ipt)
    iptuple = (iptstr)    
    cur.execute("INSERT INTO Hailstones(ID) VALUES({})".format(ipt))
#the above query works in isolation

    res = str(lhailstones)[1:-1]
    cur.execute("INSERT INTO Hailstones(Stones) VALUES({})".format(res))

#for this query I am getting the following error: psycopg2.errors.SyntaxError: INSERT 
has more expressions than target columns LINE 1: INSERT INTO Hailstones(Stones) VALUES(4, 2, 1)`

I don't understand how to insert this list into this array. If it's an array why can't it accept the list?

Dave
  • 3
  • 3
  • 2
    What are the columns in your table. Also show the values in your list. – Tarik Sep 25 '21 at 02:52
  • **try** cur.execute("INSERT INTO Hailstones(Stones) VALUES(%s)", [lhailstones[1:-1]]) #assuming lhailstones is a list. – Agnij Sep 25 '21 at 04:32
  • Don't use string formatting for values, use parameter substitution as shown in the linked duplicate Q&A. You want something like ` cur.execute("INSERT INTO Hailstones(Stones) VALUES(%s)", (res,))`. See also the relevant [docs](https://www.psycopg.org/docs/usage.html#adapt-list) – snakecharmerb Sep 25 '21 at 04:54

0 Answers0