3

I'm trying to import a CSV file into a Postgres table using the psql \copy from program command.

\copy tablename from program 'cmd /c "type file.csv"' with DELIMITER ',' CSV HEADER;

However, this fails with the error message

The syntax of the command is incorrect.
COPY 0
cmd /c "type file.csv": child process exited with exit code 1

What's wrong with my syntax?

I have tried to use simply

\COPY tablename FROM 'file.csv' DELIMITER ',' CSV HEADER;

but this fails with

could not stat file "file.csv": Unknown error

because the file is larger than 1 GB (see ERROR: could not stat file "XX.csv": Unknown error).

I'm using Windows 10 and psql 11.2.

Hanna S
  • 31
  • 1
  • 2
    Try `'cmd /c type "c:\full\path\to\file.csv"'` –  Mar 08 '21 at 07:19
  • Or wait until PostgreSQL v14, where the problem has been fixed. – Laurenz Albe Mar 08 '21 at 07:42
  • Thanks @a_horse_with_no_name, moving "type" outside the double quotes and changing slashes to backslashes in the file path did the trick. – Hanna S Mar 09 '21 at 12:24
  • @HannaS I am having same issue but I dont get what you mean for moving type outside the double quotes, do you mind to answer your question or edit it with the command you wrote to try if that helps me. Thanks in advance – gcj Dec 14 '21 at 12:56
  • @HannaS I have tried with `\copy table from program 'cmd \c type "c:\data\data.csv"' with DELIMITER ',' CSV HEADER;` but doesnt seems to be doing nothing. – gcj Dec 14 '21 at 15:22

0 Answers0