使用COPY命令

时间:2017-03-08 10:24:24

标签: python postgresql csv psycopg2

我正在使用postgresql COPY命令通过以下命令将数据从本地csv(相对路径)插入postgres表

COPY edmonton.general_building_permit_table(permit_date, permit_number, year, month_number, report_permit_date, job_category, address, legal_description, neighbourhood, neighbourhood_number, job_description, building_type, work_type, floor_area, construction_value, zoning, units_added, latitude, longitude, location, count) FROM 'data/General_Building_Permits_01_2017.csv' DELIMITER ',' CSV HEADER;"

使用psycopg2 python模块执行查询。我收到了以下错误

Error could not open file "data/General_Building_Permits_02_2017.csv" for reading: No such file or directory

但是csv存在于路径中。我需要知道COPY命令是否接受相对路径?或任何其他问题?

1 个答案:

答案 0 :(得分:0)

你需要从根开始。 并使用绝对路径。

例如,您的目录应该看起来像这样。

/home/name/Desktop/asd.txt