如何使用pgadmin4在PostgreSQL中使用\copy [英] How to use \copy in postgresql with pgadmin4

查看:1508
本文介绍了如何使用pgadmin4在PostgreSQL中使用\copy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 \copy 命令制作具有相对路径的csv文件。
我使用查询从测试表制作到名为test.csv的csv文件

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

的'./test.csv',但是在pgadmin4中,它表明 \copy 命令作为语法错误(单词 \copy下带有下划线)并显示如下消息。

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


如何解决此问题?

推荐答案

\复制 是默认命令行界面 psql 。您不能从pgAdmin4(或任何其他客户端)的SQL Shell中运行它。

\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的 \copy 是SQL命令的客户端包装< a href = https://www.postgresql.org/docs/current/static/sql-copy.html rel = noreferrer> COPY 。如果您与Postgres服务器位于同一台计算机上,则可以改用 COPY

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.

这篇关于如何使用pgadmin4在PostgreSQL中使用\copy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆