Re: COPY FROM file error: could not open file ... for reading: No such file or directory

Поиск
Список
Период
Сортировка
От Szymon Guz
Тема Re: COPY FROM file error: could not open file ... for reading: No such file or directory
Дата
Msg-id CAFjNrYsE4Za_KWzmfgN1_-MG7GTw_vpMRxPk=OEjAiLqLskxdA@mail.gmail.com
обсуждение исходный текст
Ответ на COPY FROM file error: could not open file ... for reading: No such file or directory  (Ryszard Czermiński <ryszard@czerminski.net>)
Список pgsql-novice



On 4 June 2014 18:03, Ryszard Czermiński <ryszard@czerminski.net> wrote:
I am trying to import data from csv file to a table, but COPY command
fails with "No such file or directory" error message - despite the fact that the file I am trying to read is definitely there. See below.

Apparently (as a novice :) I am missing something - your help will be highly appreciated.

Best regards,
Ryszard

$ more import_from_csv.sql
CREATE TABLE addr
(STREET varchar, CITY varchar, STATE char(2), ZIP char(10));
COPY addr FROM 'addr.csv' DELIMITER ',' CSV;
$ psql -U postgres -c 'drop table addr'
DROP TABLE
$ wc -l addr.csv
2 addr.csv
$ psql -U postgres -f import_from_csv.sql
CREATE TABLE
psql:import_from_csv.sql:3: ERROR:  could not open file "addr.csv" for reading: No such file or directory
$ psql --version
psql (PostgreSQL) 9.3.4
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04 LTS"


Hi,
COPY is run by the Postgres server, and the path is relative to the server path, or absolute, but on the server machine. If you want to use a path from client, use \COPY, which is a psql's command.

COPY with a file name instructs the PostgreSQL server to directly read from or write to a file. The file must be accessible to the server and the name must be specified from the viewpoint of the server. When STDIN or STDOUT is specified, data is transmitted via the connection between the client and the server.
http://www.postgresql.org/docs/9.2/static/sql-copy.html

Szymon

В списке pgsql-novice по дате отправления:

Предыдущее
От: Ryszard Czermiński
Дата:
Сообщение: COPY FROM file error: could not open file ... for reading: No such file or directory
Следующее
От: nitsuj
Дата:
Сообщение: pgAdmin III newie question