0

I'm trying to create a python script that will copy a glob result into postgres. This is what I have:

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()

I'm pretty new to all of this so any help is very welcome! thanks

4

1 回答 1

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()
于 2013-07-28T20:52:08.560 回答