简体   繁体   English

如何以 CSV 格式导出表格?

[英]How to export a table in CSV format?

I have a logs table in the data base database.我在数据库数据库中有一个日志表。 For the second day I'm struggling to upload it in CSV format.第二天,我正在努力以 CSV 格式上传它。

Commands like类似的命令

copy logs to 'D:/CSV.csv' WITH CSV DELIMITER ',' HEADER;将日志复制到 'D:/CSV.csv' WITH CSV DELIMITER ',' HEADER;

don't help.不要帮忙。 The error logs relation does not exist always pops up, while an empty CSV file is created along the path specified in the command.错误日志关系不存在总是弹出,同时沿命令中指定的路径创建一个空的 CSV 文件。

Either you are connected to a different database, or the schema ( public ?) is not on your search_path .要么您连接到不同的数据库,要么架构( public ?)不在您的search_path上。 In the latter case, use在后一种情况下,使用

COPY public.logs TO 'D:/CSV.csv' (FORMAT 'csv', DELIMITER ',', HEADER);

Solving the problem:解决问题:

Before using the command使用命令之前

Copy logs To 'D:/CSV.csv' With CSV DELIMITER ',' HEADER;将日志复制到 'D:/CSV.csv' 使用 CSV DELIMITER ',' HEADER;

Needed:需要:

  1. Log in to psql with the command psql -U username (according to the postgres standard)使用命令psql -U username登录到 psql(根据 postgres 标准)

  2. The next step is to connect to the database where your table is located.下一步是连接到您的表所在的数据库。 In my case, this is \connect "data base"就我而言,这是\connect "data base"

  3. And then you can copy the table in csv format with the command above.然后您可以使用上面的命令复制 csv 格式的表格。

I hope that this answer will help all newcomers in the same trouble.我希望这个答案能帮助所有遇到同样麻烦的新人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM