#coding:utf8 import psycopg2 import codecs import json conn = psycopg2.connect(dbname="BiddingKM_test_10000",user="postgres",password="postgres",host="192.168.2.101") cursor = conn.cursor() with codecs.open("C:\\Users\\User\\Desktop\\bxkc.zhongbiao_extraction_test.json", "r", encoding="utf8") as f: text = "["+f.read().replace("}","},")[:-1]+"]" index = 0 for item in json.loads(text,encoding="utf8"): index += 1 print(index) id = item["document_id"] first = item["first_tenderer"] second = item["second_tenderer"] third = item["third_tenderer"] #print(name,reference) sql = " update articles set first_tenderer='"+str(first)+"',second_tenderer='"+str(second)+"',third_tenderer='"+str(third)+"' where id='"+str(id)+"' " cursor.execute(sql) if index%1000==0: conn.commit() f.close() conn.commit() conn.close()