Hello everyone, I have the following code:

c.execute("SELECT id FROM test_table WHERE name = (?) ", (first_name,)) data_2 = c.fetchall() c.execute("INSERT INTO wo_table(wo_name) VALUES(?)", (data_2,)) conn.commit() 

The problem is that I constantly get an error:

Error binding parameter 0 - probably unsupported type.

I want to get the person's id under this name, and transfer it to another table that expects this id.

  • print(type(first_name)) that prints? - gil9red
  • Writes a list ...... - roma
  • That's the point, he needs a simple type: string, number, etc. - gil9red
  • I tried to make it in str () but in the id base it looks like this: [(1,)]. - roma

1 answer 1

fetchall() returns a list of tuples. You need one value inside the tuple inside the list. Example:

 #!/usr/bin/env python import sqlite3 db = sqlite3.connect(':memory:') # use in-memory database for the demo # create table & populate it name = "Tom" db.execute('CREATE TABLE Names (name TEXT)') db.execute('INSERT INTO Names VALUES (?)', [name]) # get value name = db.execute("SELECT name FROM Names LIMIT 1").fetchone()[0] # insert it & show results db.execute('INSERT INTO Names VALUES (?)', [name]) names = db.execute("SELECT name FROM Names").fetchall() print(names) 

Result

 [(u'Tom',), (u'Tom',)] 
  • Thanks running1 - roma