Home > front end >  How to deal with error:SQL Error [58P01]?
How to deal with error:SQL Error [58P01]?

Time:01-08

I'm learning PostgreSQL, and i run into problem: I have created table and trying to export it, but I have all the time same error

SQL Error [58P01]: ERROR: could not open file "D:\Janis\Mācības\SQL\Test\typestest.txt" for writing: No such file or directory
Hint: COPY TO instructs the PostgreSQL server process to write a file. You may want a client-side facility such as psql's \copy.

Script that I'm running:

CREATE TABLE char_data_types (
    varchar_column varchar(10),
    char_column char(10),
    text_column text
);

INSERT INTO char_data_types
VALUES
    ('abc', 'abc', 'abc'),
    ('defghi', 'defghi', 'defghi');

COPY char_data_types TO 'D:\Janis\Mācības\SQL\Test\typestest.txt'
WITH (FORMAT CSV, HEADER, DELIMITER '|');

I have taken off all possible security restriction from file typestest.txt

CodePudding user response:

There is no directory D:\Janis\Mācības\SQL\Test on the PostgreSQL server. Note that COPY writes to the database server, no the client (the statement runs on the server, and the server cannot access the client machine).

To export the data to the client machine, you have to use psql so that you can use \copy:

\copy char_data_types TO 'D:\Janis\Mācības\SQL\Test\typestest.txt' WITH (FORMAT CSV, HEADER, DELIMITER '|')

The command has to be in a single line.

  • Related