如何将表数据从PostgreSQL(pgAdmin)导出到CSV文件?

时间:2018-12-14 10:05:16

标签: postgresql pgadmin-4 postgresql-copy

我正在使用pgAdmin 4.3版,我想将一个表数据导出到CSV文件。我使用了这个查询

COPY (select * from product_template) TO 'D:\Product_template_Output.csv' DELIMITER ',' CSV HEADER;

但显示错误

  

不允许相对路径对文件使用COPY

请问如何解决此问题?

5 个答案:

答案 0 :(得分:7)

在查询编辑器中,执行查询后,您只需单击“下载为 CSV (F8)”按钮或使用 F8 键。

来源pgAdmin 4 Query Toolbar

Export button location

答案 1 :(得分:0)

您必须删除双引号:

COPY (select * from product_template) TO 'D:\Product_template_Output.csv'
   DELIMITER ',' CSV HEADER;

答案 2 :(得分:0)

尝试以下命令:

COPY (select * from product_template) TO 'D:\Product_template_Output.csv' WITH CSV;

答案 3 :(得分:0)

使用绝对路径或cd已知位置并忽略该路径。 例如,将cd放入 documents 目录,则您的命令将如下所示。

假设您要从命令行使用PSQL。

\COPY (select * from product_template) TO 'Product_template_Output.csv' DELIMITER ',' CSV HEADER;

结果将是当前工作目录中的_Product_template_Output.csv _。

再次使用 psql

答案 4 :(得分:0)

使用pgAdmin4 GUI非常简单。

您可以参考https://www.pgadmin.org/docs/pgadmin4/3.x/import_export_data.html