0

I have a list of strings:

setdata = cursor.execute("SELECT * from TABLE_NAME")
for s in setdata:
   searchid = s.Id
   summary = s.Summary

Output

   ['abuse', 'accuse', 'axis', 'decrease']
   ['crime', 'frodge']

I have to Insert the above output into another SQL table as:

sid  searchid     keywords
-----------------------------
1      122        abuse
2      122        accuse
3      122        axis
4      122        decrease
5      123        crime
6      123        frodge

How can I insert the data in this way?

6
  • Concatenate all the lists, then use executemany() to insert them all. Commented Feb 25, 2020 at 4:25
  • @Barmar Multiple lists are being generated from the loop, How do we concatenate them for get into one . Commented Feb 25, 2020 at 4:30
  • full_list = sum(list_of_lists, []) Commented Feb 25, 2020 at 4:31
  • See stackoverflow.com/questions/3021641/… for all the different ways to combine lists into one big list. Commented Feb 25, 2020 at 4:33
  • 1
    @Neeraj The sid column should ideally be auto increment; you don't set that value, your database does. Commented Feb 25, 2020 at 4:36

0

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.