How to execute postgres' sql queries from batch file?

后端 未结 7 1525
小蘑菇
小蘑菇 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

    I agree with Spidey:

    1] if you are passing the file with the sql use -f or --file parameter

    When you want to execute several commands the best way to do that is to add parameter -f, and after that just type path to your file without any " or ' marks (relative paths works also):

    psql -h %host% -p 5432 -U %user% -d %dbname% -f ..\..\folder\Data.txt
    

    It also works in .NET Core. I need it to add basic data to my database after migrations.

提交回复
热议问题