copy data from csv to postgresql using python

前端 未结 8 1176
遥遥无期
遥遥无期 2021-02-04 03:32

I am on windows 7 64 bit. I have a csv file \'data.csv\'. I want to import data to a postgresql table \'temp_unicommerce_status\' via a python script.

My Script is:

8条回答
  •  我在风中等你
    2021-02-04 04:03

    Use the copy_from cursor method

    f = open(r'C:\Users\n\Desktop\data.csv', 'r')
    cur.copy_from(f, temp_unicommerce_status, sep=',')
    f.close()
    

    The file must be passed as an object.

    Since you are coping from a csv file it is necessary to specify the separator as the default is a tab character

提交回复
热议问题