Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
不能;抄袭自;与博士后及;python_Python_Postgresql_Import_Copy_Psycopg2 - Fatal编程技术网

不能;抄袭自;与博士后及;python

不能;抄袭自;与博士后及;python,python,postgresql,import,copy,psycopg2,Python,Postgresql,Import,Copy,Psycopg2,作为主题,这是代码,没有错误消息,但数据没有插入。 这是我的代码,有人能告诉我有什么问题吗 import psycopg2 import sys import os import glob import csv #open the csv folder dictfile='******' os.chdir(dictfile) total=[] for file in glob.glob("*.csv"): total.append(file) con = None try:

作为主题,这是代码,没有错误消息,但数据没有插入。 这是我的代码,有人能告诉我有什么问题吗

import psycopg2
import sys
import os
import glob 
import csv

#open the csv folder
dictfile='******'
os.chdir(dictfile)
total=[]
for file in glob.glob("*.csv"):
    total.append(file)
con = None
try: 
    con = psycopg2.connect(host='localhost',database='*****',user='postgres', password='*****') 
    cur = con.cursor()
    for i in range(0,1):   
        filename='/Users/Shared'+'/'+total[0]
        print filename
        #better move all files into shared folder
        x="copy public.crossref_sample from "+ "'"+filename+"'"+" DELIMITERS ',' CSV"
        print x
        cur.execute(x)  
except psycopg2.DatabaseError, e:
    print 'Error %s' % e    
    sys.exit(1) 
finally:
    if con:
        con.close()

正如@a_horse_with_no_name所暗示的,您正在关闭PostgreSQL数据库连接,但您没有首先提交事务

如果尚未打开一个事务,psycopg2将为您打开一个事务。它期望您在完成工作后提交此事务

除非显式提交事务,否则关闭连接将回滚已完成的任何工作


在最后一个复制命令之后尝试
con.commit()

我在代码中没有看到提交