Postgres使用Copy命令将表导出成csv文件的遇到Permission Denied等错误

COPY (select id as ID, description as TNAME from my_table order by id) to ‘C:/exp4analyze/MyTable.csv’ with csv header;

ERROR: could not open file “C:/exp4analyze/MyTable.csv” for writing: No such file or directory

原因:目录不存在


COPY (select id as ID, description as TNAME from my_table order by id) to ‘C:/exp4analyze/MyTable.csv’ with csv header;

ERROR: could not open file “C:/Users/exp4analyze/MyTable.csv” for writing: Permission denied

原因:不能将导出路径放在系统文件夹下(C盘其他文件夹可以)


COPY (select id as ID, description as TNAME from my_table order by id) to ‘D:/exp4analyze/MyTable.csv’ with csv header;

Query returned successfully: 279 rows affected, 12 msec execution time.

正确结果


PS:如果出现 Invalid Argument 错误,考虑是“命令行”窗口或“pgAdmin”工具缺少管理员权限的原因。

你可能感兴趣的:(PostgreSQL,数据库技术)