我正在尝试创建一个将glob结果复制到postgres的python脚本。这就是我所拥有的:
import psycopg2, glob
sitesizetemp = glob.glob('C:/Data/Sheltered BLPUs/CSVs/sitesize*.csv')
conn = psycopg2.connect("dbname=postgres user=postgres")
cur = conn.cursor()
cur.execute("COPY sitesize FROM" sitesizetemp "DELIMITER ',' CSV;")
conn.commit()
cur.close()
conn.close()
我对这一切都很陌生,所以非常欢迎任何帮助!感谢
答案 0 :(得分:0)
import psycopg2, glob
sitesizetemp = glob.glob('C:/Data/Sheltered BLPUs/CSVs/sitesize*.csv')
conn = psycopg2.connect("dbname=postgres user=postgres")
cur = conn.cursor()
for f in sitesizetemp:
cur.execute("COPY sitesize FROM '%s' DELIMITER ',' CSV;" % f)
conn.commit()
cur.close()
conn.close()