1

I have installed source code of Postgres version 8.4.18, I am trying to create a table from .CSV file. (picture)

I have created a table successfully when, I am trying to copy the location with command COPY population from 'C:\Users\xyz\Desktop\Data8277.csv' WITH CSV HEADER; i get the following error.

Picture2

WARNING:  nonstandard use of escape in a string literal
LINE 1: COPY population from 'C:\Users\xyz\Desk...
                             ^
HINT:  Use the escape string syntax for escapes, e.g., E'\r\n'.
ERROR:  could not open file "C:UsersxyzDesktop-Data8277.csv" for reading: No such file or directory.

Unable to sort this problem out

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
Sam
  • 19
  • 3
  • 1
    Double the backslashes. –  Dec 20 '22 at 16:11
  • Or use dollar quoting: `select $$'C:\Users\xyz\Desk..'$$; 'C:\Users\xyz\Desk..'` per [Lexical Structure](https://www.postgresql.org/docs/8.4/sql-syntax-lexical.html) *4.1.2.4. Dollar-Quoted String Constants*. – Adrian Klaver Dec 20 '22 at 23:28
  • Yes the issue has been resolved, now m getting an error that ERROR: syntax error at or near "‘" LINE 1: ...'C:\Users\Zadane\Downloads\Popdata.csv' DELIMITER ‘,’ CSV HE... ^ And if I remove delimiter, I get error COPY population FROM 'C:\Users\Zadane\Downloads\Popdata.csv' CSV HEADER; ERROR: could not open file "C:\Users\Zadane\Downloads\Popdata.csv" for reading: No such file or directory – Sam Dec 21 '22 at 11:20
  • Try with forward slashes: `C:/Users/Zadane/Downloads/Popdata.csv`. – Adrian Klaver Dec 21 '22 at 15:39

1 Answers1

2

Set the parameter standard_conforming_strings to on, so that backslash in string literals is treated as a normal character. I hope you aren't using an ancient version like that for anything but for preparing an upgrade.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263