谢谢楼上的,下面是我根据你的回答写的代码,-------------------------------------------------------------------------------------- @echo off echo. C:\aipo_develop\PostgreSQL\8.1\bin\psql --host=XXX.XX.X.XX --port=5432 --username=XXXXX --password=XXXX XXXXXX -f=C:\・・・\dateReport.sqlecho. echo. pause ---------------------------------------------------------------------------------------- 执行提示:option dosen't take an argument -- password这是咋子一回事尼?
sorry 看错了哈! --password是提示密码,没有密码可以用--no-password psql --host=your_host --port=your_port --username=your_name --password your_database -f dateReport.sqlpsql --host=your_host --port=your_port --username=your_name --no-password your_database -f dateReport.sqlE:\pgsql\bin>psql --help psql is the PostgreSQL interactive terminal.Usage: psql [OPTION]... [DBNAME [USERNAME]]General options: -c, --command=COMMAND run only single command (SQL or internal) and exit -d, --dbname=DBNAME database name to connect to (default: "coolwind") -f, --file=FILENAME execute commands from file, then exit -l, --list list available databases, then exit -v, --set=, --variable=NAME=VALUE set psql variable NAME to VALUE -X, --no-psqlrc do not read startup file (~/.psqlrc) -1 ("one"), --single-transaction execute command file as a single transaction --help show this help, then exit --version output version information, then exitInput and output options: -a, --echo-all echo all input from script -e, --echo-queries echo commands sent to server -E, --echo-hidden display queries that internal commands generate -L, --log-file=FILENAME send session log to file -n, --no-readline disable enhanced command line editing (readline) -o, --output=FILENAME send query results to file (or |pipe) -q, --quiet run quietly (no messages, only query output) -s, --single-step single-step mode (confirm each query) -S, --single-line single-line mode (end of line terminates SQL command) Output format options: -A, --no-align unaligned table output mode -F, --field-separator=STRING set field separator (default: "|") -H, --html HTML table output mode -P, --pset=VAR[=ARG] set printing option VAR to ARG (see \pset command) -R, --record-separator=STRING set record separator (default: newline) -t, --tuples-only print rows only -T, --table-attr=TEXT set HTML table tag attributes (e.g., width, border) -x, --expanded turn on expanded table outputConnection options: -h, --host=HOSTNAME database server host or socket directory (default: "l ocal socket") -p, --port=PORT database server port (default: "5432") -U, --username=USERNAME database user name (default: "coolwind") -w, --no-password never prompt for password -W, --password force password prompt (should happen automatically)
@echo off echo. set PGPASSWORD=your_password C:\aipo_develop\PostgreSQL\8.1\bin\psql --host=XXX.XX.X.XX --port=5432 --username=XXXXX XXXXXX -f=C:\・・・\dateReport.sqlecho. echo. pause
psql执行的时候不输入密码的设定 客户一下发过来了很多的*.sql文件,用于创建数据库表。如果一个一个的运行,肯定会浪费时间。这样我做了批处理文件(Bat文件),来一次操作多个*.sql,但是,这个时候遇到一个问题,因为我的批处理是这样写的: @echo off for %%c in (*.sql) do psql -d ucom -U ucom_user -f %%c pause 这样,psql每运行一个*.sql文件的时候都要你输入一次密码,真是烦透了。如何才能不输入密码,让这些文件一次被处理掉哪?到网上查了一下,还真有办法。 Windwos环境下,创建%APPDATA%\postgresql\pgpass.conf这样一个文件,文件中的内容设定为: hostname:port:database:username:password 其中hostname是主机地址,port是数据库端口,后面的三个参数分别是数据库名,登陆用户和登陆密码。比如我的文件是这样设定的localhost:5432:ucom:ucom_user:ucom_user。这样再去执行上面的批处理,一次就OK了,再不用反复输入密码了。其中,变量%AppData%是一个对Application Data路径的简记形式,一般情况下可能是: C:\Documents and Settings\[User Name]\Application Data目录。
非常感谢你的回复。刚刚有时间来看一下这个问题。 现在是这么写的-------------------------------------------------------- @echo off echo. C:\\bin\psql --host=localhost --port=5432 --username=XXXXX --password XXXXXX -f=C:\....\dateReport.sqlecho. echo. pause -------------------------------------------------------------------------------- dateReport.sql里边只有一句话 ---------------------------- select dateReport(); ----------------------------现在的结果是 psql: warning:extra command-line argument "-f=C:\.....\dateReport.sql ignored Password for user postgres: --输入密码后 Type: \copyright for distribution terms \n for help with SQL commands \? for help with psql commands \g or terminate with semicolon to execute query \q to quit DBName=#
@echo off
echo. C:\aipo_develop\PostgreSQL\8.1\bin\psql --host=XXX.XX.X.XX --port=5432 --username=XXXXX --password=XXXX XXXXXX -f=C:\・・・\dateReport.sqlecho.
echo. pause ----------------------------------------------------------------------------------------
执行提示:option dosen't take an argument -- password这是咋子一回事尼?
--password是提示密码,没有密码可以用--no-password
psql --host=your_host --port=your_port --username=your_name --password your_database -f dateReport.sqlpsql --host=your_host --port=your_port --username=your_name --no-password your_database -f dateReport.sqlE:\pgsql\bin>psql --help
psql is the PostgreSQL interactive terminal.Usage:
psql [OPTION]... [DBNAME [USERNAME]]General options:
-c, --command=COMMAND run only single command (SQL or internal) and exit
-d, --dbname=DBNAME database name to connect to (default: "coolwind")
-f, --file=FILENAME execute commands from file, then exit
-l, --list list available databases, then exit
-v, --set=, --variable=NAME=VALUE
set psql variable NAME to VALUE
-X, --no-psqlrc do not read startup file (~/.psqlrc)
-1 ("one"), --single-transaction
execute command file as a single transaction
--help show this help, then exit
--version output version information, then exitInput and output options:
-a, --echo-all echo all input from script
-e, --echo-queries echo commands sent to server
-E, --echo-hidden display queries that internal commands generate
-L, --log-file=FILENAME send session log to file
-n, --no-readline disable enhanced command line editing (readline)
-o, --output=FILENAME send query results to file (or |pipe)
-q, --quiet run quietly (no messages, only query output)
-s, --single-step single-step mode (confirm each query)
-S, --single-line single-line mode (end of line terminates SQL command)
Output format options:
-A, --no-align unaligned table output mode
-F, --field-separator=STRING
set field separator (default: "|")
-H, --html HTML table output mode
-P, --pset=VAR[=ARG] set printing option VAR to ARG (see \pset command)
-R, --record-separator=STRING
set record separator (default: newline)
-t, --tuples-only print rows only
-T, --table-attr=TEXT set HTML table tag attributes (e.g., width, border)
-x, --expanded turn on expanded table outputConnection options:
-h, --host=HOSTNAME database server host or socket directory (default: "l
ocal socket")
-p, --port=PORT database server port (default: "5432")
-U, --username=USERNAME database user name (default: "coolwind")
-w, --no-password never prompt for password
-W, --password force password prompt (should happen automatically)
echo.
set PGPASSWORD=your_password
C:\aipo_develop\PostgreSQL\8.1\bin\psql --host=XXX.XX.X.XX --port=5432 --username=XXXXX XXXXXX -f=C:\・・・\dateReport.sqlecho.
echo. pause
客户一下发过来了很多的*.sql文件,用于创建数据库表。如果一个一个的运行,肯定会浪费时间。这样我做了批处理文件(Bat文件),来一次操作多个*.sql,但是,这个时候遇到一个问题,因为我的批处理是这样写的:
@echo off
for %%c in (*.sql) do psql -d ucom -U ucom_user -f %%c
pause
这样,psql每运行一个*.sql文件的时候都要你输入一次密码,真是烦透了。如何才能不输入密码,让这些文件一次被处理掉哪?到网上查了一下,还真有办法。
Windwos环境下,创建%APPDATA%\postgresql\pgpass.conf这样一个文件,文件中的内容设定为:
hostname:port:database:username:password 其中hostname是主机地址,port是数据库端口,后面的三个参数分别是数据库名,登陆用户和登陆密码。比如我的文件是这样设定的localhost:5432:ucom:ucom_user:ucom_user。这样再去执行上面的批处理,一次就OK了,再不用反复输入密码了。其中,变量%AppData%是一个对Application Data路径的简记形式,一般情况下可能是: C:\Documents and Settings\[User Name]\Application Data目录。
现在是这么写的--------------------------------------------------------
@echo off
echo. C:\\bin\psql --host=localhost --port=5432 --username=XXXXX --password XXXXXX -f=C:\....\dateReport.sqlecho.
echo. pause
--------------------------------------------------------------------------------
dateReport.sql里边只有一句话
----------------------------
select dateReport();
----------------------------现在的结果是
psql: warning:extra command-line argument "-f=C:\.....\dateReport.sql ignored
Password for user postgres: --输入密码后
Type: \copyright for distribution terms
\n for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
DBName=#
mydb=> \h execute;
Command: EXECUTE
Description: execute a prepared statement
Syntax:
EXECUTE name [ ( parameter [, ...] ) ]
C:\....\dateReport.sql 最好写成C:/..../dateReport.sql 必要的时候可以用"括起来哈
execute是执行prepared statement的select dateReport();是没错的
错在-f=C:\....\dateReport.sql
应该改为反斜杆
修改了
改成-f=C:/.../dateReport.sql可还是报以前的错误
psql: warning:extra command-line argument "-f=C:/...../dateReport.sql ignored这是为什么呢?
psql --host=XXX.XX.XX.XX --port=5432 --username=XXXXX --file=D:\XXX.sql
set PGUSER=
set PGPASSWORD=
psql .....