1

I am trying to execute this command:

PS C:\Program Files\PostgreSQL\9.4\bin> .\psql.exe -h front.linux-pgsql01.qa.local -p 5432 -d site -U qa -w -c "Delete from product_factor_lolek; COPY product_factor_lolek FROM E'C:\\OP_data\\SEARCH\\1.csv' delimiter '^' CSV;"

My file is located on this path: C:\OP_data\SEARCH\1.csv. But in fact, I've got an error:

ERROR: could not open file "C:\OP_data\SEARCH\1.csv" for reading: No such file or directory

I am using Windows server, PostgreSQL 9.4. What should I write for correct path?

P.S. I can't use \COPY

Michel Milezzi
  • 10,087
  • 3
  • 21
  • 36
Anton Erjomin
  • 183
  • 1
  • 1
  • 9

1 Answers1

1

The COPY command will attempt to access your CSV file on Server (front.linux-pgsql01.qa.local), not in the client. So you must send your CSV to there and point the command to its path or use stdin as you mentioned:

psql.exe -h front.linux-pgsql01.qa.local -p 5432 -d site -U qa -w -c "Delete from product_factor_lolek; COPY product_factor_lolek FROM STDIN' delimiter '^' CSV;" < C:\OP_data\SEARCH\1.csv
Michel Milezzi
  • 10,087
  • 3
  • 21
  • 36
  • Ok, but what if I want to use .csv file on my local machine? Should I use "STDIN" for this one? And if Yes, how can I do this? – Anton Erjomin May 17 '17 at 15:09
  • 1
    @AntonErjomin Yes, it's possible. See my edited answer. – Michel Milezzi May 17 '17 at 19:21
  • Unfortunatelly, I still have an error message: `PS C:\Program Files\PostgreSQL\9.4\bin> .\psql.exe -h front.linux-pgsql01.qa.local -p 5432 -d site -U qa -w -c "Delete from product_factor_lolek; COPY product_factor_lolek FROM STDIN delimiter '^' CSV;" < C:\\OP_data\\SEARCH\\1.csv At line:1 char:165 + ... iter '^' CSV;" < C:\\OP_data\\SEARCH\\1.csv + ~ The '<' operator is reserved for future use. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : RedirectionNotSupported` – Anton Erjomin May 18 '17 at 08:19
  • @AntonErjomin What's your Windows Server version? – Michel Milezzi May 18 '17 at 12:14
  • @AntonErjomin Please see this [answer](http://stackoverflow.com/a/2148816/7925366) to do a workaround on this problem. It's related with your Windows Version. – Michel Milezzi May 18 '17 at 12:16