1

I am trying to extract data from MongoDB and write back it to Postgres. The following script works fine but string inserting as individual character which contains multiple entry.

For example: Instead of

'Apple' its inserting 'A', 'P', 'P' ,'L' ,'E'

for line in results:
    name = line['name']
    cur.execute("""INSERT INTO xyz(Column1) VALUES('%s')""" % \
                (line['name']))
jmc
  • 13
  • 4

1 Answers1

0

if name is a list ['A', 'P', 'P', 'L', 'E'] then you can combine it into a single string with the string method join:

name = ''.join(list['name'])
cur.execute("""INSERT INTO xyz(Column1) VALUES('%s')""" %name)

Note that your original code doesn't use the name variable you've created.

import random
  • 3,054
  • 1
  • 17
  • 22