3

I need to copy table data into text file on Windows in csv format. How to do that?

What I have tried:

COPY test TO '"E:\\test.csv"' DELIMITER ',' CSV HEADER;

I am receiving an error while executing this query. That test.csv file have to create first before copying data into that.

ERROR: relative path not allowed for COPY to file SQL state: 42602

4
  • Check this link stackoverflow.com/questions/30130039/… Commented Sep 19, 2018 at 14:48
  • i have tried already but failed Commented Sep 19, 2018 at 15:25
  • 3
    You have both single and double quotes around your file path. Try removing the double quotes. Commented Sep 19, 2018 at 15:34
  • If it is remote server running on *nix OS then absolute Win path interpreted as relative on it. Commented Sep 19, 2018 at 15:39

1 Answer 1

2

This will work providing you have permissions. It will put the csv file at the root directory of the same drive that Postgresql is installed on, probably C:

COPY test TO '\test.csv' DELIMITER ',' CSV HEADER;
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.