psql /copy “没有那个文件或目录”
psql /copy “No such file or directory”
我在我的 postgres 服务器上创建了一个名为 "new_test" 的 table,我正在尝试从本地 Mac 上名为 "test.csv" 的 CSV 文件复制到我的新 table。我的 "new_test" table 和我的 "test.csv" 文件都有一列名为 "compkey"。我在 csv 文件中只有 4 行。可能psql命令如下:
\copy new_test(COMPKEY) from ‘TEST.csv’ with delimiter ‘,’ csv header;
但我不断收到此错误消息:‘TEST.csv’: No such file or directory
我已尝试 \cd
找到正确的文件路径,并确认我在 \! ls
所在的正确文件夹中,看到列出的 "TEST.csv" 文件。我也在 Mac 上试过绝对路径,像这样:
\copy new_test(COMPKEY) from '/Users/the/rest/of/the/file/path/TEST.csv’ with delimiter ‘,’ csv header;
...但我收到相同的错误消息。我做错了什么或遗漏了什么?
您在绝对路径中缺少前导斜杠。它应该从根开始。因此下面应该工作:
\copy new_test(COMPKEY) from '/Users/the/rest/of/the/file/path/TEST.csv' with delimiter ',' csv header;
文章示例:https://www.linux.com/blog/absolute-path-vs-relative-path-linuxunix
An absolute path is defined as the specifying the location of a file
or directory from the root directory(/)
我在我的 postgres 服务器上创建了一个名为 "new_test" 的 table,我正在尝试从本地 Mac 上名为 "test.csv" 的 CSV 文件复制到我的新 table。我的 "new_test" table 和我的 "test.csv" 文件都有一列名为 "compkey"。我在 csv 文件中只有 4 行。可能psql命令如下:
\copy new_test(COMPKEY) from ‘TEST.csv’ with delimiter ‘,’ csv header;
但我不断收到此错误消息:‘TEST.csv’: No such file or directory
我已尝试 \cd
找到正确的文件路径,并确认我在 \! ls
所在的正确文件夹中,看到列出的 "TEST.csv" 文件。我也在 Mac 上试过绝对路径,像这样:
\copy new_test(COMPKEY) from '/Users/the/rest/of/the/file/path/TEST.csv’ with delimiter ‘,’ csv header;
...但我收到相同的错误消息。我做错了什么或遗漏了什么?
您在绝对路径中缺少前导斜杠。它应该从根开始。因此下面应该工作:
\copy new_test(COMPKEY) from '/Users/the/rest/of/the/file/path/TEST.csv' with delimiter ',' csv header;
文章示例:https://www.linux.com/blog/absolute-path-vs-relative-path-linuxunix
An absolute path is defined as the specifying the location of a file or directory from the root directory(/)