How to use \copy in postgresql with pgadmin4

主宰稳场 提交于 2019-12-23 19:08:08

问题


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 (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.

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?


回答1:


\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.

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.




回答2:


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';


来源:https://stackoverflow.com/questions/41196030/how-to-use-copy-in-postgresql-with-pgadmin4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!