The error message is the same with super user using COPY. The files are located on the same server as the postgres server. Saw many similar posting but not a single one answer my question.
\copy table_name from '/path/to/csv/file.csv'
with format csv, header true ;
ERROR: syntax error at or near "format"
Tied with parenthesis or not. Read the manual at version 10 for postgres carefully. Not helping. I must be missing some minor point, please point out.
Best Answer
psql "meta-commands"
Commands in psql that start with back-slash (
\
) are called "meta-commands" and they don't follow the usual semicolon rules but are instead terminated by a newline. A small excerpt fromman psql
Much more said on this in the man pages. Yes, it's weird and annoying. It's because historically psql commands were a sort of metacommand you'd want to run without interrupting any query you were building, like \d to see columns of a table. But for pseudo-statements like
\copy
it gets confusing.What's happening here
In your case, what's happening is that
psql
runs the first line, then sends the second to the postgres server, which recognisesWITH
as a valid CTE statement token then gets confused byFORMAT
.What you want is,