如何在带有 pgadmin4 的 postgresql 中使用 \copy
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41196030/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use \copy in postgresql with pgadmin4
提问by ???
I want to use the \copy
command to make csv file with relative path.
I used a query to make from test table to csv file named test.csv
我想使用该\copy
命令制作具有相对路径的 csv 文件。我使用查询从测试表到名为 test.csv 的 csv 文件
\copy (SELECT * FROM test) to './test.csv' with csv
But in postgresql pgadmin4, it shows that \copy
command as a syntax error (there is an underline under the word '\copy') and shows a message like below.
但是在 postgresql pgadmin4 中,它将该\copy
命令显示为语法错误(“\copy”一词下有一个下划线)并显示如下消息。
ERROR: syntax error at or near "/" LINE 2: /copy (SELECT * FROM test) to './persons_client.csv' with cs... ^ ********** Error ********** ERROR: syntax error at or near "/" SQL state: 42601 Character: 2
ERROR: syntax error at or near "/" LINE 2: /copy (SELECT * FROM test) to './persons_client.csv' with cs... ^ ********** Error ********** ERROR: syntax error at or near "/" SQL state: 42601 Character: 2
How can I solve this problem?
我怎么解决这个问题?
回答by Erwin Brandstetter
\copy
is a meta-command of the default command-line interface psql. You cannot run it from the SQL shell of pgAdmin4 (or any other client). Run it from psql instead.
\copy
是默认命令行界面psql的元命令。您不能从 pgAdmin4(或任何其他客户端)的 SQL shell 运行它。而是从 psql 运行它。
psql's \copy
is a client-side wrapper for the SQL-command COPY
. If you are on the same machine as the Postgres server you might be able to use COPY
instead.
psql\copy
是 SQL 命令的客户端包装器COPY
。如果您与 Postgres 服务器在同一台机器上,您或许可以使用它COPY
。
回答by abautista
What I did to solve this problem was to execute:
我为解决这个问题所做的是执行:
psql=# copy tmp from '/path/to/file.csv' with delimiter ',' csv header encoding 'windows-1251';