psql复制到csv [英] psql copy to csv

查看:97
本文介绍了psql复制到csv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在postgresql中像这样运行时,我得到成功的结果...

in postgresql when running like this I get successful result...

\copy (select * from user) To 'test.csv' DELIMITER ',' CSV Header;

但是当我这样运行时,它会失败...

but when I run like this it fails...

\copy
(select * from user)
To 'test.csv' DELIMITER ',' CSV Header;

LINE 2: To 'test.csv' DELIMITER ',' CSV Header;

有人可以建议如何用第二种模式执行...

can someone suggest how to execute with second pattern...

推荐答案

psql (PostgreSQL命令行客户端)命令以反斜杠开头,并以return终止,而不是分号。分号终止SQL命令,但是 \COPY 不是SQL命令。 COPY 不带反斜杠将是一个SQL命令。 psql 命令写在一行上。

psql (the PostgreSQL command line client) commands are preceded with a backslash and terminated by return, not a semicolon. A semicolon terminates SQL commands, but \COPY is not SQL command. COPY without a leading backslash would be a SQL command. psql commands are written on a single line.

psql 命令在客户端计算机上运行,​​而SQL命令在服务器上运行。如果连接到远程服务器,则 \COPY 将在客户端文件系统上使用csv文件,而 COPY 将使用文件在服务器文件系统上。

psql commands are run in your client machine, while SQL commands are run in the server. If you connected to a remote server, \COPY would use a csv file on your client filesystem and COPY a file on server filesystem.

这篇关于psql复制到csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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