gpt4 book ai didi

PostgreSQL:将数据导出到 csv 文件

转载 作者:行者123 更新时间:2023-11-29 12:25:09 25 4
gpt4 key购买 nike

我想将某个 PostgreSQL 数据库的表中的数据导出到 csv 文件。由于标准复制命令不起作用,我尝试了以下操作:

\copy (SELECT * FROM persons) to 'C:\tmp\persons_client.csv' with csv

就像在 http://www.postgresqltutorial.com/export-postgresql-table-to-csv-file/ .路径似乎是正确的;但是,我收到错误消息

FEHLER:  Syntaxfehler bei »\«
LINE 1: \copy [...]

表示复制语句前的“\”处有语法错误。有什么我错过的想法吗?

顺便说一句,这不是我目前面临的真正问题。实际上我试图导入一个 csv 文件,但不幸的是我似乎没有足够的权限,当只使用“复制”时,权限将被拒绝。所以我尝试使用“\copy”导入文件,但仍然收到与尝试使用“\copy”导出时相同的错误消息。

最佳答案

\copy (SELECT * FROM persons) to 'C:\tmp\persons_client.csv' with csv 在 pgAdmin 中不起作用,因为 \copy 是一个 pslq metacommand :

Performs a frontend (client) copy. This is an operation that runs an SQL COPY command, but instead of the server reading or writing the specified file, psql reads or writes the file and routes the data between the server and the local file system. This means that file accessibility and privileges are those of the local user, not the server, and no SQL superuser privileges are required.

关于PostgreSQL:将数据导出到 csv 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44022977/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com