我正在尝试将数据从txt文件导入到postgresql数据库中的模式内创建的特定表。
import psycopg2
conn = psycopg2.connect("host='localhost' port='5432' dbname='WODR' user='Sam' password='fazilpola'")
print "Connection to database is successful"
cur = conn.cursor()
f= open ("file2.txt")
cur.copy_from(f, meteo_dane, sep = ',')
f.close()
conn.commit()
conn.close()
现在尝试上面的代码会给我一个错误:
Traceback (most recent call last):
File "database.py", line 7, in <module>
cur.copy_from(f, meteo_dane, sep = ',')
NameError: name 'meteo_dane' is not defined