postgresql 在 postgres 中使用 COPY FROM - 本地文件的绝对文件名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7571636/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-20 23:19:20  来源:igfitidea点击:

Using COPY FROM in postgres - absolute filename of local file

postgresql

提问by leddy

I'm trying to import a csv file using the COPY FROM command with postgres.

我正在尝试使用带有 postgres 的 COPY FROM 命令导入一个 csv 文件。

The db is stored on a linux server, and my data is stored locally, i.e. C:\test.csv

db存储在linux服务器上,我的数据存储在本地,即C:\test.csv

I keep getting the error:

我不断收到错误:

ERROR: could not open file "C:\test.csv" for reading: No such file or directory SQL state: 58P01

错误:无法打开文件“C:\test.csv”进行阅读:没有这样的文件或目录 SQL 状态:58P01

I know that I need to use the absolute path for the filename that the server can see, but everything I try brings up the same error

我知道我需要使用服务器可以看到的文件名的绝对路径,但我尝试的一切都会带来同样的错误

Can anyone help please? Thanks

有人可以帮忙吗?谢谢

回答by a_horse_with_no_name

Quote from the PostgreSQL manual:

引用自 PostgreSQL 手册:

The file must be accessible to the server and the name must be specified from the viewpoint of the server

该文件必须可供服务器访问,并且必须从服务器的角度指定名称

So you need to copy the file to the server before you can use COPY FROM.

所以你需要先将文件复制到服务器,然后才能使用 COPY FROM。

If you don't have access to the server, you can use psql's \copy command which is very similar to COPY FROM but works with local files. See the manual for details.

如果您无权访问服务器,则可以使用 psql 的 \copy 命令,该命令与 COPY FROM 非常相似,但适用于本地文件。有关详细信息,请参阅手册。