I have encountered these error messages when uploading a table from local to a remote server:

COPY schemaname.tablename 
FROM 'path/src/data/file.csv' WITH delimiter E'\t' CSV QUOTE AS '"' HEADER;
ERROR .....
HINT:  COPY FROM instructs the PostgreSQL server process to read a file. You may want a client-side facility such as psql's \copy.

And when I added the backslash to the copy command, this shown:

error: \copy: parse error at end of line
psql:sql/file.sql:60: ERROR:  syntax error at or near "FROM"
LINE 1: FROM 'path/src/data/file.c...

QUICK FIX:

  • Add the backslash in front of the copy command - \COPY
  • Make the whole command in one line instead of two.
\COPY schemaname.tablename FROM 'path/src/data/file.csv' WITH delimiter E'\t' CSV QUOTE AS '"' HEADER;

Another error

ERROR: unquoted carriage return found in data
HINT: Use quoted CSV field to represent carriage return.
CONTEXT: COPY filename, line 123456

My fix:

sed -i '' '123456s/\r//' data/filename.csv data/filename.csv