python - Incorrect number of bindings SQL -
i'm generating n random numbers between 0-100. n relies on amount of rows there in table_1. there's 200 rows. 200 random numbers in list returned.
i'm trying insert these 200 numbers list individual rows table_2's random_number column. there no link between random numbers , 3 other columns in table_2.
r = [random.randint(0,100) rows in cursor.execute('select * table_1')] r in rows: cursor.execute('update table_2 set random_number = (?)', r)
this have. a
programmingerror: incorrect number of bindings supplied. current statement uses 1, , there 4 supplied
error. i've seen other solutions ad (?, ) doesnt work. i've tried:
r = [random.randint(0,100) rows in cursor.execute('select * table_1')] r = str(r) cursor.execute('insert table_2 (random_number) values (?)', [','.join(r)])
which running, nothing being inserted random_number column.
i think problem rows no longer in scope when access in loop, nor list you'd want iterate over.
if understood correctly should change script this:
# generate random list r_list = [random.randint(0,100) rows in cursor.execute('select * table_1')] # iterate on list , insert r in r_list: cursor.execute('insert table_2 (random_number) values (?)', r)
Comments
Post a Comment