1

I would like to import a local csv file into a table on a db in the cloud. I know this is a recurring issue for users, but I have not found a clear, concise answer for my situation, which I believe to be common.

My question: How do I use the correct COPY or \copy command? (I have zero psql experience) How do I format the location of the file I want to import?

My situation: I only have pgAdmin on my local Windows computer, from which I am running the sql code. The db I am connected to is in the cloud. I am not a superuser, but have write permissions to the table I'm attempting to add data to.

1 Answer 1

1

Use the psql command line client

Change to the directory where the file is located

The command should be something like:

PGHOST=hostname PGDATABASE=dbname psql -c "\copy tableName from 'file.csv' with (format csv)"

You might need to set PGUSER and PGPASSWORD variables too

Docs are here: https://www.postgresql.org/docs/current/static/app-psql.html

Sign up to request clarification or add additional context in comments.

3 Comments

Where is the command line client? I'm using the latest pgAdmin 4 V2.1
@otterdog2000 I don't know about pgAdmin 4. It used to come with pgAdmin III
I found it, thanks. I typed psql in my explorer search and the sql shell came up. I don't think I had it with my pgAdmin III install.

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.