1

I am using pgAdmin 4 and am looking to download query results as INSERT statements rather than as a CSV (the only option I can find). I am used to doing this with MySQL Workbench, but maybe I have been spoiled over there?

Is it possible in pgAdmin 4 to download query results as INSERT statements?

  • @dezso New to Postgres; used to MySQL. And I can't use the COPY TO a csv file and then COPY FROM a csv file solution I've found elsewhere because I can't write files on the database server I'm working with. – wogsland Apr 4 '17 at 15:58
  • You might use either pgAdmin 4 to export/import the CSVs for you, or (in my opinion better) use \copy from psql. The latter gives you the same functionality as the native COPY, but it writes/reads to/from the machine where the client is running. – dezso Apr 4 '17 at 16:00
  • @dezso I have 2 Postgres database servers. One has data in it and I can access it with pgAdmin 4. I want to move the data to the other one where I have only command line psql access and no text editor to write a csv file with. This is why copy doesn't seem to be the write path to go down. – wogsland Apr 4 '17 at 16:12
1

If you need this for moving data among databases, as you indicate in your comments, I'd suggest using psql and its \copy command.

This will definitely work, as it writes the files onto the local machine (the one the client is running on, eg. your laptop), and if you can connect using pgAdmin 4, you can also connect using psql.

The process would look like

psql -h dbhost -U whatever -d yourdb
psql> \copy table_name TO ~/table_name.csv WITH (FORMAT csv)
psql> \q

psql -h other-dbhost -U whatever -d your_other_db
psql> \copy other_table FROM ~/table_name.csv WITH (FORMAT csv)

The file location syntax assumes you are on Linux.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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