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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Manish
  • 49
  • 1
  • 10
  • Concatenate all the lists, then use `executemany()` to insert them all. – Barmar Feb 25 '20 at 04:25
  • @Barmar Multiple lists are being generated from the loop, How do we concatenate them for get into one . – Manish Feb 25 '20 at 04:30
  • `full_list = sum(list_of_lists, [])` – Barmar Feb 25 '20 at 04:31
  • See https://stackoverflow.com/questions/3021641/concatenation-of-many-lists-in-python for all the different ways to combine lists into one big list. – Barmar Feb 25 '20 at 04:33
  • @Barmar -Thanks for the response , - We can't do like the same as have to insert the List according to the separate text row ID inside a loop. – Manish Feb 25 '20 at 04:35
  • 1
    @Neeraj The `sid` column should ideally be auto increment; you don't set that value, your database does. – Tim Biegeleisen Feb 25 '20 at 04:36

0 Answers0