单击即可在postgresql中运行批处理文件

时间:2017-12-04 09:23:58

标签: windows postgresql batch-file postgresql-9.4 pgadmin

Hello专家我已经批量文件在postgresql中运行查询它按下回车键4次后无需输入就可以正常工作。 1个服务器,2个数据库,3个端口和4个密码。单击即可获得相同的结果。 `

@echo off
REM Copyright (c) 2012-2016, EnterpriseDB Corporation.  All rights reserved

REM PostgreSQL server psql runner script for Windows

cmd.exe /c chcp 1252

SET server=localhost
SET /P server="Server [%server%]: "

SET database=naari
SET /P database="Database [%database%]: "
SET Password=pes

SET port=5432
SET /P port="Port [%port%]: "

SET username=postgres
SET /P username="Username [%username%]: "

for /f "delims=" %%a in ('chcp ^|find /c "932"') do @ SET CLIENTENCODING_JP=%%a
if "%CLIENTENCODING_JP%"=="1" SET PGCLIENTENCODING=SJIS
if "%CLIENTENCODING_JP%"=="1" SET /P PGCLIENTENCODING="Client Encoding [%PGCLIENTENCODING%]: "
REM Run psql
"C:\Program Files\PostgreSQL\10\bin\psql.exe" -h %server% -U %username% -d %database% -p %port% -f e:\DELETE.sql
pause

`

1 个答案:

答案 0 :(得分:1)

现在我有了解决方案。

@echo off
REM Copyright (c) 2012-2016, EnterpriseDB Corporation.  All rights reserved

REM PostgreSQL server psql runner script for Windows

cmd.exe /c chcp 1252

REM Run psql
"C:\Program Files\PostgreSQL\10\bin\psql.exe" -h localhost -U postgres -d naari -p 5432 -f e:\script.sql

pause