Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I am a novice in psql and need some help. How can I load a local CSV to a remote DB?

I am using the following command

\COPY test(user_id, product_id, value) 
      FROM '/Users/testuser/test.tsv' WITH DELIMITER '\t' CSV HEADER;

but this searches the file on the remote DB while I need to do that on my local PC.

share|improve this question

closed as unclear what you're asking by dezso, RolandoMySQLDBA, billinkc, Max Vernon, Mark Storey-Smith Nov 16 '13 at 2:07

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

2  
\copy reads a local file (it's a psql command and can only be used from inside psql). COPY however (note the missing ``) will read the file on the server. –  a_horse_with_no_name Apr 4 '13 at 14:53
    
so there is no way to this? i need to copy the file to the remote server? –  user22149 Apr 4 '13 at 14:58
    
is there any difference in copy and \copy? sorry i am really new in psql only know oracle there i can do this without any problem –  user22149 Apr 4 '13 at 15:02
    
Well the difference is, that one reads the file on the server and the other is reading the file on the client. Obviously reading the file on the server will be faster. –  a_horse_with_no_name Apr 4 '13 at 15:07
1  
@user22149 Use a literal tab or E'\t' . But tab should be the default if you don't specify a delim anyway. –  Craig Ringer Apr 4 '13 at 23:53
show 2 more comments

1 Answer

There are two possibilities here.

  1. If you are using psql, then \copy is the correct way to do things as you mention.

  2. If you are using a client program you have authored, then you need to

    COPY FROM STDIN.....
    

And then feed the file in (see the documentation on the COPY command.

The COPY command is a slightly strange beast. It is the one command PostgreSQL currently supports from Quel and so it is both non-standard, and based on something of a different paradigm than the rest of the commands. For this reason it's important to read the docs relatively carefully on this command.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.