Run query via batch file in postgresql

Viewed 1030

Hello expert I want to refresh materialized view in postgresql via batch file. I don't have any idea how to connect postgresql database via batch file. I have to run following query via batch file - "REFRESH MATERIALIZED VIEW deposit.mv_transaction_view"

1 Answers

Update: based on comments, filled in all the parameters required to connect to a database "planet" with user, port and password information. The quotes are really for the shell, for easy replacement.

You can do this with psql.

psql -Upostgres -p5432 -c "REFRESH MATERIALIZED VIEW deposit.mv_transaction_view" planet

and put that in the batch file or script or whatever.

With this in your ~/.pgpass file:

localhost:5432:planet:postgres:pes

or variants thereof. You can also use

*:*:*:postgres:pes
Related