如何将csv数据导入Postgres表?

时间:2014-09-01 10:48:21

标签: postgresql import-from-csv

以下是查询:

COPY public.project(project_number,project_name,country) from '\\server\csv\projects_export.csv' DELIMITERS ',' CSV;

此查询的结果是:  
                        

 ERROR:  could not open file "\\server\csv\projects_export.csv" 
 for reading: No such file or directory.

请指导我

1 个答案:

答案 0 :(得分:0)

您需要在单引号字符串文字中转义/加倍反斜杠字符。这是文字Windows文件名的常见问题。 COPY 的文档特别警告http://www.postgresql.org/docs/9.2/static/sql-copy.html

Dollar quoting是最简单的选择:

COPY public.project(project_number,project_name,country) from $$\\server\Softwel\Projects\projects\csv\projects_export.csv$$ DELIMITERS ',' CSV;