Postgresql – getting insert queries from pgAdmin 4

pgadmin-4postgresql

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?

Best Answer

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.