0

I am having an issue trying to run \copy command where my column name is desc

I've tried the following:

psql -U user -p 1234 -h hostname -c "\copy schema.table (desc) from /my/file.txt WITH DELIMITER '|' HEADER CSV " db
psql -U user -p 1234 -h hostname -c "\copy schema.table ('desc') from /my/file.txt WITH DELIMITER '|' HEADER CSV " db
psql -U user -p 1234 -h hostname -c "\copy schema.table ("desc") from /my/file.txt WITH DELIMITER '|' HEADER CSV  db

I get the same error everytime:

ERROR:  syntax error at or near "desc"

I can't seem to get around it. Is there something that I am missing?

1 Answer 1

1

just escape double quotes, like here:

vao@vao-X102BA:~$ psql -c "copy s1(\"desc\") from stdin;"
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>> b
>> \.
COPY 1
vao@vao-X102BA:~$ psql
psql (9.6.3)
Type "help" for help.

vao=# select * from s1;
 i | desc
---+------
   | a
   | b

(2 rows)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.