4

I have following psql query to insert data to database

sql = ("INSERT INTO kart_user (custid,token,cycle,userid,proxyid,salesrepid,users,buyer,salesrep,validfrom,validto,discount,category,ratioOnly,proxy,notified) ""VALUES (%s, %s, %s, %s,%s, %s, %s, %s,%s, %s, %s, %s,%s, %s, %s, %s)")
result = self.cur.execute(sql,data)
self.dbconn.commit()
return result

Now, the problem I facing ,in some case data may contain multiple rows.in this case how can i rewrite my code. Note: I don't like to use for loop for data iteration ,please suggest better way to solve this issue.

1
  • Maybe this is what you are looking for: code Good luck! Commented Jan 18, 2016 at 11:38

1 Answer 1

4

executemany() would help:

result = self.cur.executemany(sql, data)

data in this case should be a list of lists or a list of tuples.

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.