python db insert
<p>I am in facing a performance problem in my code.I am making db connection a making a select query  and then inserting in a table.Around 500 rows in one select query ids populated .Before inserting i am running select query around 8-9 times first and then inserting then all using cursor.executemany.But it is taking 2 miuntes to insert which is not qood .Any idea </p>

<pre><code>def insert1(id,state,cursor):

   cursor.execute("select * from qwert where asd_id =%s",[id])

   if sometcondition:

        adding.append(rd[i])

cursor.executemany(indata, adding)
</code></pre>

<p>where rd[i] is a aray for records making and indata is a insert statement</p>

<pre><code>#prog start here


cursor.execute("select * from assd")



for rows in cursor.fetchall()

if rows[1]=='aq':


  insert1(row[1],row[2],cursor)

if rows[1]=='qw':

  insert2(row[1],row[2],cursor)
</code></pre>
