Reputation: 52638
If I remote into a postgres database on heroku with heroku pg:psql -a appname
I can wait a few seconds for it to connect, then run \copy (SELECT * FROM users) TO users.csv CSV DELIMITER ',' HEADER
to extract a table from the remote database to my desktop.
However, if I put these two lines of code into a .bat file and run it, it opens cmd.exe and connects to the postgres database (as expected), but then nothing happens (no more code is executed)
How do you construct the .bat file so that it runs the first line (to connect to the remote database), then executes the subsequent lines inside the remotely connected database?
Upvotes: 1
Views: 196
Reputation: 22023
You would have to pass the command to psql with the -c switch.
psql -c "\copy (SELECT * FROM users) TO users.csv CSV DELIMITER ',' HEADER"
If you need to execute more commands it will be easier to put them in a seperate file and pass that to psql with the -f switch.
Upvotes: 1