How to execute postgres' sql queries from batch file?

后端 未结 7 1524
小蘑菇
小蘑菇 2021-02-08 14:36

I need to execute SQL from batch file. I am executing following to connect to Postgres and select data from table

C:/pgsql/bin/psql -h %DB_HOST% -p 5432 -U %DB_         


        
7条回答
  •  野性不改
    2021-02-08 15:10

    if running on Linux, this is what worked for me (need to update values below with your user, db name etc)

    psql "host=YOUR_HOST port=YOUR_PORT dbname=YOUR_DB_NAME user=YOUR_USER_NAME password=YOUR_PASSWORD" -f "fully_qualified_path_to_your_script.sql"
    

提交回复
热议问题